i need help with this question
Show older comments
I am supposed to find the number of timesteps i.e the number of steps taken but my answer is incorrect any inputs on my code will be a major help thanks.Also has the advection equation with the center spaced method used correctly ?
N=200;
x=linspace(-10,10,N);
dx=x(2)-x(1);
c=-0.9;
t=0;
dt=0.2;
timestep=0;
f=@(x)exp(-5*x.^2);
y=f(x)';
figure(1),plot(x,y)
title(['Current time=',num2str(t)])
drawnow
%using centered space
A=eye(N)-(0.5*c*(dt/dx))*((diag(ones(N-1,1),1)-diag(ones(N,1),0)));
while abs(y(end))<0.001 && abs(y(1))<0.001
y=A*y;
t=t+dt;
timestep=timestep+1;
figure(1),cla
plot(x,y)
hold on
plot(x,f(x-c*t),'r')
title(['Current time=',num2str(t)])
drawnow
end
6 Comments
All we know is the code. We cannot know, why you assume, that the answer is wrong. Without any further details it is impossible to miodify a code, such that it produces the output you expect. So please edit the question, exoplain, which problem you want to solve and why you assume, that there is a bug.
dulanga
on 7 May 2019
dulanga
on 7 May 2019
Answers (0)
Categories
Find more on Just for fun in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

