I'm not that familiar with matlab. I solve a first differential equation of the form dS(t)/dt = F(S(t)) (S(0) given) using ode45. But then, I have a second differential equation to solve which is dX(t)/dt = G(X(t),S(t)) (X(0) given). How can I use the results on S to solve the equation on X ?
I want the values S(1) and G(1) of the solutions S (and G). The first idea I had was quite "naive". I first create a function which gives me the value S(t) for t in [0,1] :
function dS=equation1(t,S)
dS=F(S);
end
function S=solve1(S0,t)
if t==0
S=S0;
else
[~,V]=ode45(@equation1,[0 t],S0);
S=V(end,:)
end
And then I create a second function to solve the second equation :
function dX=equation2(t,X)
dX=G(X,solve1(t));
end
function G=solve2(X0,t)
[~,V]=ode45(@equation2,[0 t],X0);
end
and in the end, G(1)=solve2(X0,1) and S(1)=solve1(S0,1). But I feel like there is a much better way to do it ! Thanks for your help !