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

1 view (last 30 days)
Tarun Agarwal on 25 Jul 2021
Commented: Tarun Agarwal on 25 Jul 2021
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 CommentsShowHide 1 older comment
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 =

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.
##### 2 CommentsShowHide 1 older comment
Tarun Agarwal on 25 Jul 2021
@Jan Thank you very much It worked
@darova@Yongjian Feng Thanks a lot .

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.

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by