I am solving a linear spring mass damper system with the following equation:
The code I used was this:
[Td,Yd]=ode45(@(t,y) damped_spring_mass(F,m,k,w,c,t,y),tspan,y0);
function dy=damped_spring_mass(F,m,k,w,c,t,y)
dy(2)=(F*cos(w*t)-k*x-c*v)/m;
The code was downloaded from code, contributed by author. This worked fine until I tried to do something like this: by changing the last line of function into this:
dy(2)=(F*cos(w*t)-k*x^2-c*v)/m;
It showed a warning and the graph was wrong
Warning: Failure at t=4.169703e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.421085e-14) at
I also tried this
But this one gave a good result.
Whenever exponent of x is even, I was getting warnings and graphs were wrong.
Can someone help me with the problem here? Thank you.