I have problem with simplifing my equation

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 3 Oct 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.
  2 Comments
shahin hashemi
shahin hashemi on 3 Oct 2020
hi again walter
i have small quastion and i really appreciated if u could help 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);
end
do u think is it possible to use integral (numerical integration) base on r
for YY1 ?
and consider r for 0:1
and can u plz help me with the code and do you think the answer is relaible ?
tanx again

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by