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

2 views (last 30 days)
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 Comments
Jan
Jan on 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 = 

Sign in to comment.

Accepted Answer

Jan
Jan on 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.

More Answers (1)

Yongjian Feng
Yongjian Feng on 25 Jul 2021
Edited: Yongjian Feng on 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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!