symbolic calculation error in code
2 views (last 30 days)
Show older comments
YOGESHWARI PATEL
on 22 Mar 2021
Commented: YOGESHWARI PATEL
on 24 Mar 2021
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 Comments
Accepted Answer
Walter Roberson
on 22 Mar 2021
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 Comments
Walter Roberson
on 24 Mar 2021
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.
More Answers (0)
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!