I have problem with simplifing my equation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
shahin hashemi
el 3 de Oct. de 2020
Editada: shahin hashemi
el 3 de Oct. de 2020
Dear all
i have cod like below :
clc
clear all
a=1;
m=9;
u=[3.8317 7.0156 10.1735 13.3237 16.4706 19.6159 22.7601 25.9037 29.0468 ];
syms r
for j=1:m
for i=1:100;
yy1(i)=(((-1)^(i-1))/((factorial(i-1))*(factorial(i))))*(((u(j))*r)/2)^(2*(i-1)+1) ;
end
YY1(j)=sum(yy1);
jj1(j)=eval(YY1(j));
end
answer give me :
jj1 =
[ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]
even if i make :
r=1
eval(jj1)
again :
eval (jj1)
ans =
Columns 1 through 8
NaN NaN NaN NaN NaN NaN NaN NaN
Column 9
NaN
but when i run this cod :
clc
clear all
for i=1:100;
y1(i)=(((-1)^(i-1))/((factorial(i-1))*(factorial(i))))*(z/2)^(2*(i-1)+1) ;
end
Y1=sum(y1);
z=1;
eval(Y1)
answer give me :
ans =
0.4401
they only different at Fixed coefficient
u(j)/2
0 comentarios
Respuesta aceptada
Walter Roberson
el 3 de Oct. de 2020
Works for me.
a=1;
m=9;
u=[3.8317 7.0156 10.1735 13.3237 16.4706 19.6159 22.7601 25.9037 29.0468 ];
R = 1;
syms r
jj1 = zeros(1,m);
YY1 = zeros(1,m,'sym');
for j=1:m
yy1 = zeros(1,100,'sym');
for i=1:100
yy1(i)=(((-1)^(i-1))/((factorial(i-1))*(factorial(i))))*(((u(j))*r)/2)^(2*(i-1)+1) ;
end
YY1(j)=sum(yy1);
jj1(j) = double(subs(YY1(j), r, R));
end
You should never eval() a symbolic expression.
eval() of a symbolic expression is equivalent to eval(char()) of the expression. However, char() of a symbolic expression is not generally a MATLAB expression.
>> char(repmat(sym('x'),[2 2 2]))
ans =
'array(1..2, 1..2, 1..2, (1, 1, 1) = x, (1, 1, 2) = x, (1, 2, 1) = x, (1, 2, 2) = x, (2, 1, 1) = x, (2, 1, 2) = x, (2, 2, 1) = x, (2, 2, 2) = x)'
char() of a symbolic expression is also not generally a MuPAD expression.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!