How to get values (by interpolation?) of a function f(x), not knowing its analitical expression, to use them in ode45

1 view (last 30 days)
I have this ode to solve
g''(x)+f(x)g'(x)
with:
g(0)=0 and g'(0)=0.5
So
xspan=linspace(0,10,100);
y0=[0 0.5];
[x,y] = ode45(@(x,y)odefun(x,y,f),xspan,y0);
I know f(x) at each x-span, since I get it from the solution of another ode. My odefun should be like this:
function dy=odefun(x,y,f)
dy(1) = y(2);
dy(2) = -f(x)*y(2);
dy = dy(:);
end
But the question is how the get the f(x) at each of the steps at which the ode45 solver internally works. I thought to interpolate the f at each internal step used by the ode45, using the known values with x-span, but I don't know how I can take those steps and even if this is possible. Is there any solution (not needs in the way I suggested) to the problem? Thanks in advance.

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!