Info

この質問は閉じられています。 編集または回答するには再度開いてください。

# Problem with computing integral of a function

1 回表示 (過去 30 日間)
Tristan Blackledge 2019 年 10 月 28 日

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 件のコメント表示 なし非表示 なし
Shubham Gupta 2019 年 10 月 28 日
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);

### 回答 (1 件)

Shubham Gupta 2019 年 10 月 28 日

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)

### Community Treasure Hunt

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

Start Hunting!