EULER'S METHOD FOR 2ND ODE

13 views (last 30 days)
Andres Cardenas
Andres Cardenas on 9 Dec 2019
Edited: Andres Cardenas on 9 Dec 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')

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations 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!