Please someone help test run this Matlab code and debug it if possible. Please help a student
1 次查看(过去 30 天)
显示 更早的评论
alpha=input('simulation time alpha=') [x,t] = meshgrid(-4:.1:4, 0.1:.2:0.4); exact=(sech(x/4-t/4)).^2 f0=(sech(x/4)).^2 f1=1/2.*(sech(x/4)).^2.*tanh(x/4)+1/2.*(sech(x/4)).^4.*tanh(x/4) f2=7/8.*(sech(x/4)).^6.*(tanh(x/4)).^2-1/8.*(sech(x/4)).^6 +5/4.*(sech(x/4)).^4.*(tanh(x/4)).^2-1/4.*(sech(x/4)).^4 +3/8.*(sech(x/4)).^2.*(tanh(x/4)).^2-1/8.*(sech(x/4)).^2 f3=35/16.*(sech(x/4)).^8.*(tanh(x/4)).^3-11/6.*(sech(x/4)).^8.*tanh(x/4) +17/4.*(sech(x/4)).^6.*(tanh(x/4)).^3-13/8.*((sech(x/4))).^6.*tanh(x/4) +39/16.*(sech(x/4)).^4.*(tanh(x/4)).^3-19/16.*(sech(x/4)).^4.*tanh(x/4) +3/8.*(sech(x/4)).^2.*((tanh(x/4)).^3)-1/4.*(sech(x/4)).^2.*tanh(x/4) f4=385/64.*(sech(x/4)).^8.*(tanh(x/4)).^4-35/16.*sech(x/4).*tanh(x/4)-51/16 .*(sech(x/4)).^8.*(tanh(x/4)).^2+153/16.*(sech(x/4)).^6.*(tanh(x/4)).^4 +11/16.*sech(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^8.*tanh(x/4) .*(-1/2.*(sech(x/4)).^2.*tanh(x/4))-17/4.*sech(x/4).*(-1/2.*(sech(x/4)).^2 .*tanh(x/4)).^6.*tanh(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^3+11/64 .*(sech(x/4)).^8-193/32.*(sech(x/4)).^6.*(tanh(x/4)).^2+273/64 .*(sech(x/4)).^4.*(tanh(x/4)).^4+13/8.*sech(x/4).*(-1/2*(sech(x/4)).^2).^6 .*tanh(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4))-39/16.*sech(x/4) .*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^7.*tanh(x/4)+13/32.*(sech(x/4)).^6 -53/16.*(sech(x/4)).^4.*(tanh(x/4)).^2+15/32.*(sech(x/4)).^2 .*(tanh(x/4)).^4+19/16.*sech(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^5 .*tanh(x/4)-3/8.*sech(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^5.*tanh(x/4) +19/64.*(sech(x/4)).^4-15/32.*(sech(x/4)).^2.*(tanh(x/4)).^2+1/4.*sech(x/4) .*tanh(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^3-sech(x/4)-35/8 .*(sech(x/4)).^8.*(tanh(x/4)).^4+105/16.*(sech(x/4)).^8.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+11/8.*(sech(x/4)).^8.*(tanh(x/4)).^4-11/16 .*(sech(x/4)).^.8.*(1/4-1/4.*(tanh(x/4)).^2)-51/.8.*(sech(x/4)).^.6 .*(tanh(x/4)).^4+51/4.*(sech(x/4)).^6.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+39/16.*(sech(x/4)).^6.*(tanh(x/4)).^2 -13/8 .*(sech(x/4)).^6.*(1/4-1/4.*(tanh(x/4)).^2)-39/16.*(sech(x/4)).^4 .*(tanh(x/4)).^4+117/16.*(sech(x/4)).^4.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+19/16.*(sech(x/4)).^4.*(tanh(x/4)).^2-19/16 .*(sech(x/4)).^4.*(1/4-1/4.*(tanh(x/4)).^2)-3/16.*(sech(x/4)).^2 .*(tanh(x/4)).^4+9/8.*(sech(x/4)).^2.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+1/8.*(sech(x/4)).^2.*(tanh(x/4)).^2-1/4 .*(sech(x/4)).^2.*(1/4-1/4.*(tanh(x/4)).^2).^2+1/16.*(sech(x/4)).^2 u4=f0+f1.*((t.^alpha)/gamma(1+alpha))+f2.*((t.^(2.*alpha))/gamma(1+2.*alpha ))+f3.*((t.^(3.*alpha))/gamma(1+3.*alpha))+f4.*((t.^(4.*alpha))/gamma(1+4.* alpha)) Z1=uexact mesh(t,x,Z1) Z2=u4 mesh(t,x,Z2)
2 个评论
采纳的回答
Star Strider
2021-7-24
The ‘uexact’ variable does not exist, and there is nothing similar to it (for example by a different spelling, at least that I can see) in the code. Substituting ‘exact’ for it (that does exist) produces a mesh plot.
Otherwise, ‘uexact’ will need to be created for the code to work, since that appears to be the only probllem. (The input call does not work in the onlilne Run feature, so I assigned the ‘alpha’ value separately. I have no idea what it should be , so change it if the value I chose is not appropriate.)
% alpha=input('simulation time alpha=')
alpha = 100;
[x,t] = meshgrid(-4:.1:4, 0.1:.2:0.4);
exact=(sech(x/4-t/4)).^2
f0=(sech(x/4)).^2
f1=1/2.*(sech(x/4)).^2.*tanh(x/4)+1/2.*(sech(x/4)).^4.*tanh(x/4)
f2=7/8.*(sech(x/4)).^6.*(tanh(x/4)).^2-1/8.*(sech(x/4)).^6 +5/4.*(sech(x/4)).^4.*(tanh(x/4)).^2-1/4.*(sech(x/4)).^4 +3/8.*(sech(x/4)).^2.*(tanh(x/4)).^2-1/8.*(sech(x/4)).^2
f3=35/16.*(sech(x/4)).^8.*(tanh(x/4)).^3-11/6.*(sech(x/4)).^8.*tanh(x/4) +17/4.*(sech(x/4)).^6.*(tanh(x/4)).^3-13/8.*((sech(x/4))).^6.*tanh(x/4) +39/16.*(sech(x/4)).^4.*(tanh(x/4)).^3-19/16.*(sech(x/4)).^4.*tanh(x/4) +3/8.*(sech(x/4)).^2.*((tanh(x/4)).^3)-1/4.*(sech(x/4)).^2.*tanh(x/4)
f4=385/64.*(sech(x/4)).^8.*(tanh(x/4)).^4-35/16.*sech(x/4).*tanh(x/4)-51/16 .*(sech(x/4)).^8.*(tanh(x/4)).^2+153/16.*(sech(x/4)).^6.*(tanh(x/4)).^4 +11/16.*sech(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^8.*tanh(x/4) .*(-1/2.*(sech(x/4)).^2.*tanh(x/4))-17/4.*sech(x/4).*(-1/2.*(sech(x/4)).^2 .*tanh(x/4)).^6.*tanh(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^3+11/64 .*(sech(x/4)).^8-193/32.*(sech(x/4)).^6.*(tanh(x/4)).^2+273/64 .*(sech(x/4)).^4.*(tanh(x/4)).^4+13/8.*sech(x/4).*(-1/2*(sech(x/4)).^2).^6 .*tanh(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4))-39/16.*sech(x/4) .*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^7.*tanh(x/4)+13/32.*(sech(x/4)).^6 -53/16.*(sech(x/4)).^4.*(tanh(x/4)).^2+15/32.*(sech(x/4)).^2 .*(tanh(x/4)).^4+19/16.*sech(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^5 .*tanh(x/4)-3/8.*sech(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^5.*tanh(x/4) +19/64.*(sech(x/4)).^4-15/32.*(sech(x/4)).^2.*(tanh(x/4)).^2+1/4.*sech(x/4) .*tanh(x/4).*(-1/2.*(sech(x/4)).^2.*tanh(x/4)).^3-sech(x/4)-35/8 .*(sech(x/4)).^8.*(tanh(x/4)).^4+105/16.*(sech(x/4)).^8.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+11/8.*(sech(x/4)).^8.*(tanh(x/4)).^4-11/16 .*(sech(x/4)).^.8.*(1/4-1/4.*(tanh(x/4)).^2)-51/.8.*(sech(x/4)).^.6 .*(tanh(x/4)).^4+51/4.*(sech(x/4)).^6.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+39/16.*(sech(x/4)).^6.*(tanh(x/4)).^2 -13/8 .*(sech(x/4)).^6.*(1/4-1/4.*(tanh(x/4)).^2)-39/16.*(sech(x/4)).^4 .*(tanh(x/4)).^4+117/16.*(sech(x/4)).^4.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+19/16.*(sech(x/4)).^4.*(tanh(x/4)).^2-19/16 .*(sech(x/4)).^4.*(1/4-1/4.*(tanh(x/4)).^2)-3/16.*(sech(x/4)).^2 .*(tanh(x/4)).^4+9/8.*(sech(x/4)).^2.*(tanh(x/4)).^2 .*(1/4-1/4.*(tanh(x/4)).^2)+1/8.*(sech(x/4)).^2.*(tanh(x/4)).^2-1/4 .*(sech(x/4)).^2.*(1/4-1/4.*(tanh(x/4)).^2).^2+1/16.*(sech(x/4)).^2
u4=f0+f1.*((t.^alpha)/gamma(1+alpha))+f2.*((t.^(2.*alpha))/gamma(1+2.*alpha ))+f3.*((t.^(3.*alpha))/gamma(1+3.*alpha))+f4.*((t.^(4.*alpha))/gamma(1+4.* alpha))
% Z1=uexact
Z1 = exact;
figure
mesh(t,x,Z1)
xlabel('t')
ylabel('x')
zlabel('Z_1')
Z2=u4
figure
mesh(t,x,Z2)
xlabel('t')
ylabel('x')
zlabel('Z_2')
Is this the desired result?
.
7 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Conditions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!