MATLAB: I want to plot x and y for ODE45 function

ode45

i have this function
function dy = Funcion(x,y)
m=0.1; M=10;c=0.1; k=0.4; F=5*x;
dy = zeros(2,1);
dy(1) = x(2);
dy(2) = -(c*y(1) – F + k*y(2))/(M + m);
and i want to plot x and y i write
[x,y] = ode45(@Funcion,[0 10],[0.1 -1]);
plot(x,y)
this error is appear why
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, …

Best Answer

This line doesn't look correct:
dy(1) = x(2);
The first agument x in the derivative function is the independent variable and a scalar, so there is no x(2) value. Maybe you meant this:
dy(1) = y(2);
Related Question