EULER'S METHOD FOR 2ND ODE

13 vues (au cours des 30 derniers jours)
Andres Cardenas
Andres Cardenas le 9 Déc 2019
I can't figure out why I am not getting a numerical solution and consequently a graph for the my code:
t0 = 0;
t = 5;
h = 0.1;
N = (t-t0)/h;
T = [t0:h:t]';
Y = zeros(N+1,1);
Y(1) = 3;
%Start of Euler Method
syms Y(t)
E = diff(Y,2) + .1*diff(Y) + .3*Y == .02*Y^3;
V = odeToVectorField(E)
Y = sym(zeros(size(t)));
for i = 1:N
P = V(2);
Y(i+1) = Y(i) + h*P;
S = Y(i+1)
end
figure(2)
plot(T,Y,'-o')
this is the error im getting;
Error using plot
Data must be numeric, datetime, duration or an array convertible
to double.
Error in Euler (line 21)
plot(T,Y,'-o')

Réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by