フィルターのクリア

I am trying to create an array h of size 1001 which can store value of 2 integrals

3 ビュー (過去 30 日間)
gl=10;
gr=10;
N=1000;
L=10;
l=10;
h = zeros(1,1000);
syms x;
for i=1:1001
f =gl*(7/44)*(exp((-1*L*i)/(N*l*cos(x))));
A=vpa(int(f,-1.57,1.57));
A
f =gl*(7/44)*(exp((-1*(L-N)*i)/(N*l*cos(x))));
B=vpa(int(f,1.57,4.71));
B
h(i)=A+B;
end
1- On running instead of value of B I am getting exact expression is printing intead of value of B
2- I want to store all these values in the array h from index 1 to 1001 but its showing error message "Unable to convert expression into double array.".
Plase help and thanks a lot in advance.
  2 件のコメント
darova
darova 2021 年 7 月 25 日
Try double instead of vpa
Jan
Jan 2021 年 7 月 25 日
@darova: This does not work also. See:
gl=10;
gr=10;
N=1000;
L=10;
l=10;
syms x;
i = 1;
f = gl * (7 / 44) * (exp((-1 * (L-N) * i) / (N * l * cos(x))));
B = vpa(int(f, x, [1.57, 4.71]))
B = 

サインインしてコメントする。

採用された回答

Jan
Jan 2021 年 7 月 25 日
gl=10;
gr=10;
N=1000;
L=10;
l=10;
syms x;
i = 1;
f = gl * (7 / 44) * (exp((-1 * (L-N) * i) / (N * l * cos(x))));
B = vpaintegral(f, x, [1.58, 4.71]) % Smaller interval, x > pi/2
B = 
3.91702
B = vpaintegral(f, x, [1.57, 4.71]) % Original interval
B = 
For cos(x)==0, or x=pi/2 the exponent gets infinite and the integration fails due to the pole.
  2 件のコメント
Yongjian Feng
Yongjian Feng 2021 年 7 月 25 日
Ah... cos(x) is in the denominator! You are right.
Tarun Agarwal
Tarun Agarwal 2021 年 7 月 25 日
@Jan Thank you very much It worked
@darova@Yongjian Feng Thanks a lot .

サインインしてコメントする。

その他の回答 (1 件)

Yongjian Feng
Yongjian Feng 2021 年 7 月 25 日
編集済み: Yongjian Feng 2021 年 7 月 25 日
It doens't allow you to go outside (-1.57, 1.57). This is essentially (-PI/2, PI/2). Since your f(x) is a function of cos(x), so your f(x) is also a periodic function. Try to keep the integration range within (-PI/2, PI/2), and it should work.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by