For example, if I have the following ODE: y''+y=0
In Matlab I could assume y(1)=y and y(2)=y', then
dy(1)=y(2)
dy(2)=-y(1)
Now, if I have the ODE in the form of y''+f(x)*y=0, where f(x) is a function that I can evaluate its numerical value anywhere but you don't have the analytical form and can't fit f(x) to a certain function. My question is then how to numerically solve this ODE in MATLAB if I want to put the value of f(x) in the ODE, for example,
f(x)=0.1 when x<0.5 and
f(x)=1.0 when x>=0.5
This ODE might be unrealistic but it gives an idea about the problem I am facing. Please don't solve it piecewise. Is that doable? Or I have to write the ODE solver by myself?
Thanks in advance for the inputs.