필터 지우기
필터 지우기

symbolic calculation error in code

조회 수: 3 (최근 30일)
YOGESHWARI PATEL
YOGESHWARI PATEL 2021년 3월 22일
댓글: YOGESHWARI PATEL 2021년 3월 24일
syms x n
syms t
% syms m
% m=0.7;
U=zeros(1,2,'sym');
A=zeros(1,2,'sym');
B=zeros(1,2,'sym');
U(1)=exp((sqrt(2)*x)/4)/(exp((sqrt(2)*x)/4)+exp(-(sqrt(2)*x)/4));
for k=1:10
A(1)=0;
B(1)=0;
for i=1:k
A(1)=A(1)+U(i)*U(k-i+1) ;
end
for j=1:k
for r=1:j
B(1)=U(r)*U(j-r+1)*U(k-r+1);
end
end
U(k+1)=((diff(U(k),x,2)-B(1)+2*A(1)-U(k)))/k;
end
disp (U)
for k=1:10
series(x,t)=series(x,t)+U(k)*(power(t,k-1));
end
series
C=zeros(5,5);
for x=1:5
e=(x-1)/1;
for t=1:5
f=(t-1)/10;
C(x,t)=series(e,f)
end
end
vpa(C,15)
This code is not showing the answer.BUSY is also shown in the workspace.

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 22일
tic
syms x n
syms t
% syms m
% m = 0.7;
U = zeros(1,2,'sym');
A = zeros(1,2,'sym');
B = zeros(1,2,'sym');
U(1) = simplify(exp((sqrt(2)*x)/4)/(exp((sqrt(2)*x)/4)+exp(-(sqrt(2)*x)/4)));
for k = 1:10
A(1) = 0;
B(1) = 0;
for i = 1:k
A(1) = simplify(A(1)+U(i)*U(k-i+1)) ;
end
for j = 1:k
for r = 1:j
B(1) = simplify(U(r)*U(j-r+1)*U(k-r+1));
end
end
U(k+1) = simplify(((diff(U(k),x,2)-B(1)+2*A(1)-U(k)))/k);
%disp(U(k+1))
end
disp (U)
for k = 1:10
series(x,t) = simplify(series(x,t)+U(k)*(power(t,k-1)));
end
series
series(x, t) = 
C = zeros(5,5);
for x = 1:5
e = (x-1)/1;
for t = 1:5
f = (t-1)/10;
C(x,t) = series(e,f);
end
end
vpa(C,15)
ans = 
toc
Elapsed time is 47.994421 seconds.
  댓글 수: 7
Walter Roberson
Walter Roberson 2021년 3월 24일
k = 20 took about 600 seconds for me; it looks like the time increase might be cubic in k (which does not surprise me.)
So if you were planning to take this to k = 1000 like in your earlier question, you should expect on the order of 295 days to execute, if your system has enough memory.
You could attempt to rewrite the whole calculation as numeric work, in hope that would speed it up -- which would be entirely possible. However, beyond k = 245 or so, the denominator of the expression would overflow to infinity, so that is the approximate upper limit on numeric work before the calculation becomes completely useles. The calculation is likely to become mostly useless for numeric work long before that.
YOGESHWARI PATEL
YOGESHWARI PATEL 2021년 3월 24일
Thank you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by