Euler's method help
Show older comments
I am trying to plot an euler's method for dx/dt=-100x for x(t)=x(0)e^(-100t) with x(0)=1.My code is
x = 1;
h = 0.001;
n_final = 5;
n = 0;
while (n < n_final)
x(n+h) = x(n)+h*(-100*x(n));
n = n+h;
end
plot(x(n), n)
why is my code not working? I want to plot the numerical solution xn vs x.
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics 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!