Filter löschen
Filter löschen

symbolic calculation error in code

3 Ansichten (letzte 30 Tage)
YOGESHWARI PATEL
YOGESHWARI PATEL am 22 Mär. 2021
Kommentiert: YOGESHWARI PATEL am 24 Mär. 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 22 Mär. 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
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 Kommentare
Walter Roberson
Walter Roberson am 24 Mär. 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.
YOGESHWARI PATEL
YOGESHWARI PATEL am 24 Mär. 2021
Thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by