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 日

0 投票

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 件のコメント

YOGESHWARI PATEL
YOGESHWARI PATEL 2021 年 3 月 23 日
One more query you have display the value of sima 1, sigma 2.How this values are diaplayed .I think tic and toc give me the run time.
Walter Roberson
Walter Roberson 2021 年 3 月 23 日
The and so on were displayed automatically by Live Script in order to make the expression easier to read. If you are using the regular editor instead of Live Script then you can use pretty() to get something similar.
YOGESHWARI PATEL
YOGESHWARI PATEL 2021 年 3 月 24 日
Thank you .Now its working.
YOGESHWARI PATEL
YOGESHWARI PATEL 2021 年 3 月 24 日
There is a problem with the code in this part
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)
when i change the value of k in the upper loop its always showing busy
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
Walter Roberson
Walter Roberson 2021 年 3 月 24 日
Your expression gets more and more complicated as k increases, and it takes longer and longer to simplify.
However, simplification is still called for because it reduces the rate at which A and B and U get more complicated.
15 took about 201 seconds on my system. The time required appears to increase with approximately the square of k.
tic
maxk = 15;
syms x n
syms t
% syms m
% m = 0.7;
U = zeros(maxk+1,1,'sym');
A = zeros(1,1,'sym');
B = zeros(1,1,'sym');
wb = waitbar(0, 'generating U');
cleanMe = onCleanup(@() delete(wb));
U(1) = simplify(exp((sqrt(2)*x)/4)/(exp((sqrt(2)*x)/4)+exp(-(sqrt(2)*x)/4)));
Utimes = zeros(1,maxk);
for k = 1:maxk
Utic = tic;
waitbar(k/maxk, wb);
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);
Utoc = toc(Utic);
Utimes(k) = Utoc;
end
disp (U)
k = 1:maxk;
plot(k, Utimes, 'displayname', 'U generation times');
xlabel('k'); ylabel('time (s)')
p = polyfit(log(k), log(Utimes), 1);
a = exp(p(2)); b = p(1);
fprintf('Utime is approximately %.5g * k^%.5g\n', a, b);
waitbar(0, wb, 'generating series');
for k = 1:maxk
waitbar(k/maxk, wb);
series(x,t) = simplify(series(x,t)+U(k)*(power(t,k-1)));
end
series
C = zeros(5,5);
waitbar(0, wb, 'evaluating numeric')
for x = 1:5
waitbar(x/5, wb);
e = (x-1)/1;
for t = 1:5
f = (t-1)/10;
C(x,t) = series(e,f);
end
end
vpa(C,15)
delete(cleanMe);
toc
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 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by