symbolic calculation error in code
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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)
toc
7 个评论
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!