MATLAB: Dsolve problem

dsolve

Hello, I would like to use a function f in a differential equation for example f=x but get a crazy result.
syms x y f
f=x
y=dsolve('D2x=-f','x(0)=1','Dx(0)=0')
How can I put into dsolve a function f defined outside of dsolve?

Best Answer

One way would be to convert f to a string:
syms x y f
f=x
y=dsolve(['D2x=-' char(f)],'x(0)=1','Dx(0)=0')