Difference of the two functions
2 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
Walter Roberson
2021-5-29
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
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);
[X, T] = meshgrid(1:10, 1:10);
e = T/10;
u = sin(x) + sin(e);
r = abs(u-C)
surf(X, T, r)
xlabel('x');
ylabel('t');
zlabel('r')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!