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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Jan
Jan am 25 Jul. 2021
@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 = 

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 25 Jul. 2021
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.

Weitere Antworten (1)

Yongjian Feng
Yongjian Feng am 25 Jul. 2021
Bearbeitet: Yongjian Feng am 25 Jul. 2021
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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by