Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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 commentaires
darova
darova le 25 Juil 2021
Try double instead of vpa
Jan
Jan le 25 Juil 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 = 

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 25 Juil 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 commentaires
Yongjian Feng
Yongjian Feng le 25 Juil 2021
Ah... cos(x) is in the denominator! You are right.

Connectez-vous pour commenter.

Plus de réponses (1)

Yongjian Feng
Yongjian Feng le 25 Juil 2021
Modifié(e) : Yongjian Feng le 25 Juil 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by