ODE reliant on dependent function
Show older comments
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
Sara
on 6 Aug 2014
I think you can put the function C at the beginning of functiontosolve and use the current values for A and t. I am a bit confused by your code though: where is C? Is C actually C1 and C2?? You can't export C1 and C2 from the solver (it's numerically wrong), but you can reeval them in the main function.
Can you post input values for your problem (all of them) + the expression for C (or C1,C2)?
Michael
on 6 Aug 2014
Sara
on 6 Aug 2014
After this line:
function output=functiontosolve(t,x)
you can put the eqn for C's as function of x (which is the current value of A). If this does not work, then I'm not understanding the problem :(
Michael
on 7 Aug 2014
Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!