Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Problem with computing integral of a function

1 Ansicht (letzte 30 Tage)
Tristan Blackledge
Tristan Blackledge am 28 Okt. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I am having trouble with the integral part in Am=2/delta_a.*integral(Phi_o.*cos(Bm.*x),-delta_a/2,delta_a/2) and am wondering how I would be able to rewrite this with a function handle or an alternative.
D=2;
Ea=0.1;
vEf=0.12;
delta_a=10*pi;
v=0.22;
Phi_o=1;
t=1;
x1=(-delta_a/2:delta_a/2);
n=1:2:5;
Bm=n*(pi/delta_a);
lambdam=v*(D*(Bm.^2)+Ea-vEf);
Am=2/delta_a.*integral(Phi_o.*cos(Bm.*x),-delta_a/2,delta_a/2);
Phi=sum(Am*cos(Bm.*x1).*exp(-lambdam*t));
  1 Kommentar
Shubham Gupta
Shubham Gupta am 28 Okt. 2019
Your Bm & x1 has different dimensions, you cannot use Bm.*x1 in the last line.
If your dependent variable is x for the integral, what is Bm? Do you want integral value only for 1 Bm or you want it for a vector Bm. What is the size of Am you are expecting?
Anyhow, for integral you need a function. You can define it using:
func = @(x) Phi_o.*cos(Bm.*x); % make Bm scalar to use following integral
Integral_Am = integral(func,-delta_a/2,delta_a/2);

Antworten (1)

Shubham Gupta
Shubham Gupta am 28 Okt. 2019
Bearbeitet: Shubham Gupta am 28 Okt. 2019
Using some info from this question, which you have posted again. My understanding is that you want to calculate Phi at each n & Bm, Am, & lambam varies according to n(1,3,5). After calculating Phi(n) for each n you are adding by using Phi=Phi1+Phi3+Phi5. You can try following to achieve this:
D=2;
Ea=0.1;
vEf=0.12;
delta_a=10*pi;
v=0.22;
Phi_o=1;
t=1;
x1=(-delta_a/2:0.1:delta_a/2);
x2=x1';
n=1:2:5;
Bm=@(n)n*(pi/delta_a);
lambdam=@(n)v*(D*(Bm(n).^2)+Ea-vEf);
f = @(n)@(x)Phi_o.*cos(Bm(n)*x);
Am = @(n)(2/delta_a.*integral(f(n),-delta_a/2,delta_a/2));
Phif = @(n)(Am(n)*cos(Bm(n).*x2).*exp(-lambdam(n)*t));
Phi = sum(cell2mat(arrayfun(Phif,n,'Uniformoutput',false)),2);
plot(x2,Phi)

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by