Question: I need help with this MATLAB code to achive this picture: xmin = 0 ; xmax = 1 ; N = 1 0 0 ;

I need help with this MATLAB code to achive this picture:
xmin =0;
xmax =1;
N =100;
dt =0.009;
t =0.3;
tmax =0.5;
v =1;
dx =(xmax - xmin)/N;
x = xmin - dx : dx : xmax + dx;
if x 1;
u0= exp(-(1/(1-(x^2))));
else
u0=0;
u = u0;
unp1= u0;
nsteps = tmax/dt;
for n =1 : nsteps
u(1)= u(3);
u(N+3)= u(N+1);
for i =2 : N +2
unp1(i)= u(i)- vdt/dx(u(i)- u(i-1));
end
t = t + dt;
u = unp1;
exact = exp(-200(x-0.25-vt).^2);
plot(x,exact, 'r-');
hold on
plot(x,u,'bo-', 'markerfacecolor' ,'b');
hold off
axis ([xmin xmax -0.51.5])
xlabel('x','fontsize',16)
ylabel('U(t,x)','fontsize',16)
title(sprintf('time =%1.3f',t),'fontsize',16)
shg
pause(dt);
end
(c) Modify your initial code (forward upwind = forward in time + backward in space) so
that the domain is -1,1. Take g(x)={e-11-|x|2ifx1,0ifx1. Plot your solution at time
t=0.3 and t=0.5. Save your plots as PNG files.
I need help with this MATLAB code to achive this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!