Starting with this differential equation:
m*d2xdt2 + a*(dxdt)^2 + k*x= F*cos(omega*t)
The first step is to solve the equation for the highest order derivative appearing in the equation. This results in:
d2xdt2 = (F*cos(omega*t) - a*(dxdt)^2 - k*x)/m
Now rewrite this as two first order equations using a 2-element vector y, where y(1) is defined to be x and y(2) is defined to be dxdt:
dy(1)dt = dxdt = y(2)
dy(2)dt = d(dxdt)dt = d2xdt2 = (F*cos(omega*t) - a*(dxdt)^2 - k*x)/m = (F*cos(omega*t) - a*(y(2))^2 - k*y(1))/m
From that you can define a derivative function. E.g., expressed in a function handle:
a = 1;
k = 20;
m = 0.5;
F = 0.01;
omega = 2*pi;
dydt = @(t,y) [y(2);(F*cos(omega*t) - a*y(2)^2 - k*y(1))/m];
This function handle is what you can pass to ode45( ).
Best Answer