Please someone help test run this Matlab code and debug it if possible. Please help a student

1 vue (au cours des 30 derniers jours)
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 commentaires
Yongjian Feng
Yongjian Feng le 24 Juil 2021
If you can format it better, others might be able to understand what it is.
Omorodion Solomon
Omorodion Solomon le 24 Juil 2021
Please just copy and paste it on matlab; i copied it my mobile phone.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 24 Juil 2021
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
exact = 2×81
0.4042 0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869 0.9014 0.9151 0.3738 0.3888 0.4042 0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869
f0=(sech(x/4)).^2
f0 = 2×81
0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869 0.9014 0.9151 0.9280 0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869 0.9014 0.9151 0.9280
f1=1/2.*(sech(x/4)).^2.*tanh(x/4)+1/2.*(sech(x/4)).^4.*tanh(x/4)
f1 = 2×81
-0.2271 -0.2352 -0.2433 -0.2513 -0.2593 -0.2672 -0.2748 -0.2823 -0.2894 -0.2962 -0.3025 -0.3083 -0.3136 -0.3181 -0.3220 -0.3250 -0.3270 -0.3281 -0.3281 -0.3270 -0.3246 -0.3210 -0.3159 -0.3095 -0.3016 -0.2923 -0.2814 -0.2691 -0.2553 -0.2400 -0.2271 -0.2352 -0.2433 -0.2513 -0.2593 -0.2672 -0.2748 -0.2823 -0.2894 -0.2962 -0.3025 -0.3083 -0.3136 -0.3181 -0.3220 -0.3250 -0.3270 -0.3281 -0.3281 -0.3270 -0.3246 -0.3210 -0.3159 -0.3095 -0.3016 -0.2923 -0.2814 -0.2691 -0.2553 -0.2400
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
f2 = 2×81
0.1510 0.1548 0.1581 0.1609 0.1630 0.1643 0.1647 0.1641 0.1623 0.1591 0.1546 0.1484 0.1406 0.1309 0.1193 0.1056 0.0899 0.0720 0.0519 0.0296 0.0052 -0.0211 -0.0494 -0.0793 -0.1107 -0.1433 -0.1767 -0.2107 -0.2447 -0.2784 0.1510 0.1548 0.1581 0.1609 0.1630 0.1643 0.1647 0.1641 0.1623 0.1591 0.1546 0.1484 0.1406 0.1309 0.1193 0.1056 0.0899 0.0720 0.0519 0.0296 0.0052 -0.0211 -0.0494 -0.0793 -0.1107 -0.1433 -0.1767 -0.2107 -0.2447 -0.2784
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)
f3 = 2×81
-0.0540 -0.0458 -0.0356 -0.0230 -0.0080 0.0099 0.0307 0.0548 0.0823 0.1133 0.1480 0.1864 0.2284 0.2740 0.3228 0.3746 0.4288 0.4847 0.5418 0.5989 0.6552 0.7093 0.7600 0.8060 0.8459 0.8782 0.9015 0.9146 0.9163 0.9057 -0.0540 -0.0458 -0.0356 -0.0230 -0.0080 0.0099 0.0307 0.0548 0.0823 0.1133 0.1480 0.1864 0.2284 0.2740 0.3228 0.3746 0.4288 0.4847 0.5418 0.5989 0.6552 0.7093 0.7600 0.8060 0.8459 0.8782 0.9015 0.9146 0.9163 0.9057
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
f4 = 2×81
-15.9920 -15.2619 -14.5177 -13.7624 -12.9993 -12.2319 -11.4636 -10.6984 -9.9399 -9.1921 -8.4589 -7.7443 -7.0518 -6.3853 -5.7479 -5.1429 -4.5729 -4.0403 -3.5470 -3.0945 -2.6836 -2.3147 -1.9877 -1.7019 -1.4562 -1.2490 -1.0781 -0.9412 -0.8356 -0.7584 -15.9920 -15.2619 -14.5177 -13.7624 -12.9993 -12.2319 -11.4636 -10.6984 -9.9399 -9.1921 -8.4589 -7.7443 -7.0518 -6.3853 -5.7479 -5.1429 -4.5729 -4.0403 -3.5470 -3.0945 -2.6836 -2.3147 -1.9877 -1.7019 -1.4562 -1.2490 -1.0781 -0.9412 -0.8356 -0.7584
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))
u4 = 2×81
0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869 0.9014 0.9151 0.9280 0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869 0.9014 0.9151 0.9280
% Z1=uexact
Z1 = exact;
figure
mesh(t,x,Z1)
xlabel('t')
ylabel('x')
zlabel('Z_1')
Z2=u4
Z2 = 2×81
0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869 0.9014 0.9151 0.9280 0.4200 0.4362 0.4527 0.4696 0.4869 0.5045 0.5224 0.5406 0.5591 0.5777 0.5966 0.6156 0.6347 0.6540 0.6732 0.6924 0.7116 0.7306 0.7495 0.7681 0.7864 0.8044 0.8220 0.8391 0.8556 0.8716 0.8869 0.9014 0.9151 0.9280
figure
mesh(t,x,Z2)
xlabel('t')
ylabel('x')
zlabel('Z_2')
Is this the desired result?
.
  7 commentaires
Omorodion Solomon
Omorodion Solomon le 31 Juil 2021
I'm new to this environment. I've accepted your answer. Please kindly assist to plot the graph of the exact solution and approximate solution in a single graph. Kind regards!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by