ODE reliant on dependent function

1 view (last 30 days)
Michael
Michael on 6 Aug 2014
Commented: Michael on 7 Aug 2014
Hi,
So I am trying to use Matlab to solve a system of time-dependent differential equations, say vector dA/dt (not sure if I can TeX here) which have an additional dependence on a secondary vector function, C(t). The issue arises due to the secondary function being a function of A, my solution. That is,
dA/dt=f(t,C(t, A(t))).
Currently I am using ODE45, however this requires initial conditions to be given for C, which cannot be input as it is a not a function to be integrated. I'd like to know if this system can be solved with an inbuilt Matlab function or whether I should try and build a custom solver?
To be clear, here is some sample code:
[t,results]=ode45(@(t,x) functiontosolve(t,x), [0 t1],a]
function output=functiontosolve(t,x)
%Need to give C1 and C2 initial parameters so it will run
C1=b;
C2=c;
%all "p's" are parameters which can be defined inside the function.
dA1=(p1*C1)/(pa2+C1)
C1=A/((p3+(p4)/(p4+C1)+(p5)/(p6+C1))
dA2=p2*(C2-C1)-dA1;
output=[dA1;dA2]
So my issue is firstly that C1, C2 have to be given values to run, so therefore whenever MATLAB runs the function as it does in ODE45 it then always assigns those values. Secondly, I'd like the C1 and C2 values to be exported, if I could make it solve these equations simultaneously.
I may have over-complicated this, so my sincerest apologies if you have read this and think my question is nonsense or poorly phrased.
My only idea is to run ODE45 on very small intervals with initial values and then update C1, C2 and loop. This seems expensive so I'd like to know if there is an easier solution.
Thanks Michael
  5 Comments
Michael
Michael on 6 Aug 2014
Edited: Michael on 6 Aug 2014
You're answer is actually what I need for a normal situation. The difference is that C is defined implicity (and seems to not be able to be rearranged).
So the problem essentially boils down to
c=f(x,c) dx/dt=t+c
where c-f(x,c)=0 cannot be easily solved for c. The error comes from trying to define c with c, i.e. the same as x=1/(1+x). I don't have the symbolic package which I think would make this simple.
I realise this is nothing like the question I originally asked but its been really helpful going through this and I'm quite a MATLAB newb.
Michael
Michael on 7 Aug 2014
Its ok I got it with fsolve. Thanks for all your effort

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!