Euler's Method for stiff ODE
Mostrar comentarios más antiguos
Having problem with my code, I'm trying to make my graph (the middle) look like the bottom graph. I feel like it is something with the initial inputs, I pretty sure my for loop is correct. Thanks for the help I appreciate it!
if true
% %%Explicit Euler
h = 5;
x = [0:h:20];
yb = zeros(size(x));
yb(1) = 1;
yb2(1) = 1;
mu = 1;
for n = 1:length(x)-1
yb(n+1) = yb(n) + h*yb2(n);
yb2(n+1) = yb2(n) + h*(mu*(1-yb(n)^2)*yb2(n) - yb(n));
end
%%Plot
figure(1); clf(1);
plot(x,yb,'k');
hold on
plot(x,yb2,'or');
title(['Van der Pol Equation for \mu = ',num2str(mu), 'with Euler']);
xlabel('Time');
ylabel('y(t)');
legend('y_{1}', 'y_{2}','location','northeast')
end
4 comentarios
Torsten
el 1 de Mzo. de 2018
Honestly: How do you want to reproduce the curvature of the bottom graph with a step size of h=5 ???
jake thompson
el 1 de Mzo. de 2018
Torsten
el 1 de Mzo. de 2018
Could you show the plot with stepsize h=0.01, say ?
Rena Berman
el 12 de Dic. de 2019
(Answers Dev) Restored edit
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!