필터 지우기
필터 지우기

I have problem with simplifing my equation

조회 수: 2 (최근 30일)
shahin hashemi
shahin hashemi 2020년 10월 3일
편집: shahin hashemi 2020년 10월 3일
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

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 3일
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
shahin hashemi
shahin hashemi 2020년 10월 3일
tanx alot walter for ur answer
shahin hashemi
shahin hashemi 2020년 10월 3일
편집: shahin hashemi 2020년 10월 3일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by