Difference of the two functions

2 views (last 30 days)
I wrote the text for the two function as :
U=zeros(1,2,'sym');
A=zeros(1,2,'sym');
B=zeros(1,2,'sym');
C=zeros(1,2,'sym');
series(x,t)=sym(zeros(1,1));
U(1)=x^2/10
for k=1:5
A(1)=0;
C(1)=0;
for i=1:k
A(1)=simplify(A(1)+U(i)*U(k-i+1)) ;
end
for i=1:k
C(1)=simplify(C(1)+U(i)*diff(U(k-i+1),x,1));
end
U(k+1)=(simplify(2*C(1)+4*A(1)-3*U(k))))/k;
end
disp (U);
for k=1:6
series(x,t)=simplify(series(x,t)+U(k)*(power(t,k-1)));
end
series
C=zeros(10,10);
for x=1:10
for t=1:10
f=t/10;
C(x,t)=series(x,f);
end
end
u=zeros(10)
for x=1:10
for t=1:10
e=t/10;
u(x,t)=sin(x)+sin(e);
end
end
disp(u)
r=abs(u-C)
The code is showing the dimension error in the last line when is use the commmand surf(x,t,r)

Accepted Answer

Walter Roberson
Walter Roberson on 29 May 2021
format long g
syms x t real
U=zeros(1,2,'sym');
A=zeros(1,2,'sym');
B=zeros(1,2,'sym');
C=zeros(1,2,'sym');
series(x,t)=sym(zeros(1,1));
U(1)=x^2/10
U = 
for k=1:5
A(1)=0;
C(1)=0;
for i=1:k
A(1)=simplify(A(1)+U(i)*U(k-i+1)) ;
end
for i=1:k
C(1)=simplify(C(1)+U(i)*diff(U(k-i+1),x,1));
end
U(k+1)=(simplify(2*C(1)+4*A(1)-3*U(k)))/k;
end
disp (U);
for k=1:6
series(x,t)=simplify(series(x,t)+U(k)*(power(t,k-1)));
end
series
series(x, t) = 
C=zeros(10,10);
for x=1:10
for t=1:10
f=t/10;
C(x,t)=series(x,f);
end
end
u=zeros(10);
[X, T] = meshgrid(1:10, 1:10);
e = T/10;
u = sin(x) + sin(e);
r = abs(u-C)
r = 10×10
0.523851555957208 0.506789402445208 0.492776390906542 0.481415690061208 0.472163885909208 0.464356387490542 0.457232832645208 0.449962493773208 0.441669683594542 0.431459160909208 0.722653616798309 0.703898405288975 0.691960387166308 0.691238196990309 0.708118146760975 0.751437510398309 0.832947808222309 0.967778091432975 1.17489822659031 1.47758218009431 1.44164362180403 2.50279212266003 6.10748976719603 16.052326390052 38.986308329228 85.242228455204 169.66803620006 312.458207586596 539.985115257452 885.630398504228 4.36255572887939 26.2950677594714 133.255657817157 478.349819458415 1341.10325703525 3166.48012189101 6603.90124855627 12546.2623909446 22168.9524585485 36968.8717526352 19.8229411972852 272.281822238952 1696.06551994729 6559.35851557228 19080.233215364 46044.4776755723 97423.4233274473 186991.772702239 332945.427156197 558519.314595572 102.343036996182 2034.87349123551 13682.6167768387 54548.550282894 161263.792249538 393094.211265395 837447.035765027 1615377.46352637 2887095.27116816 4857471.42364744 486.214706816982 11465.6287534076 80045.373199951 324275.072734066 967217.330175915 2371013.41117988 5070948.92893626 9809519.52887291 17570496.573357 29612992.8263965 2011.22933640713 51896.873194571 370279.235488766 1514687.17947566 4542769.02445649 11175499.2158143 23960384.995051 46434673.0698246 83288556.2839865 140528380.287619 7272.05332644373 197984.223291368 1432454.84133568 5897326.84918288 17752073.0938469 43775493.7619459 94012213.8140157 182419180.418823 327512160.387682 553012237.608761 23375.5741592928 659017.281376793 4814037.32782763 19908039.8623368 60082652.1270293 148411045.90543 319107458.970564 619736716.533057 1113423752.68923 1881063131.86922
surf(X, T, r)
xlabel('x');
ylabel('t');
zlabel('r')
  1 Comment
yogeshwari patel
yogeshwari patel on 29 May 2021
Thank you and apprectiate your effort that you answer within 4 hrs

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!