How do I solve a system of equations?

Hello,
suppose I've got four equations which depend on one another and one of them depends on the time:
a = f(b);
b = f(c);
c = f(d);
d = f(a,t);
How can a system like this be solved? I thought about using one of the ode solvers but failed to implement the functions. Can anybody give me a hint?
Thanks in advance,
J

1 Commento

I am confused about you using f() with one argument in most places, but using it with two arguments for "d".

Accedi per commentare.

 Risposta accettata

Isktaine
Isktaine il 14 Ago 2012
Modificato: Isktaine il 14 Ago 2012
You need to have a function which the ode solvers can act on.
[t,y] = ode45('YourODEFunction', [0 50], [a(0) b(0) c(0) d(0)])
An example of how to create the function:
function dA=YourODEFunction(x,A)
dA(1)=f(b); %Equation for a,
dA(2)=f(c); %Equation for b
dA(3)=f(d); %Equation for c
dA(4)=f(a,t); %Equation for d
dA=dA'
Note that when you have f(b) (and all the others) you'd have to type in an experission eg
dA(1)=3*A(2) %Coding up of a=3*b
Any time your equation would have a 'b' use A(2), any time you would use an 'a' use A(1), any time you would use a 'c' use A(3) and 'd' use A(4). Does that make sense?

5 Commenti

Iskataine,
thanks for your answer. The code is running, but the results look weird. Do I have to define the equations of a,b and c as differential equations as well, even if they do not depend on 't'?
By the way: I think 'x' has to be replaced by 't' if the function for d is related to 't':
function dA=YourODEFunction(t,A)
dA(1)=f(b); %Equation for a,
dA(2)=f(c); %Equation for b
dA(3)=f(d); %Equation for c
dA(4)=f(a,t); %Equation for d
dA=dA'
Yes you are right, it should be a t - that was a typo on my part.
Why do the results look weird? You should have a vector t which is a vector with the discrete values of t used. The second vector y (or A or whatever you want to call it) should have four columns, each representing [a b c d] and each row corresponding to the t value.
As for whether you need to define each differential equation.. I'm not sure but I would think so. As d is a function of t, so is c by extension surely? Therefore so is b and hence a?
Isktaine,
I've worked with ode solvers before, but I can't get my mind around this one. The results look weird because I know what they should look like (I've implemented the code in Mathematica some time ago).
The issue with the form of the equations for a, b and c just proves that I haven't understood the way the ode solvers are working. If I have an equation that describes a system at a time t I have to hand over the derivative of that equation to the solver, right? Now, if I have some variable a which is indirectly depending on time (since a = f(d(t))) do I have to build the derivative as well? Very confusing, I will have to read the help once more...
I'm sorry! I think I misunderstood your first question then. I was assuming all of these were differentials i.e. a'=f(b). How silly of me to make that assumption! Are any of the equations actually differentials?
If there are no differentials then you have to uncouple the system before it can solved numerically. You could just use direct substitution to solve them by hand to get one equation for d only in terms of t, the use back substitution to find values for c,b and a once you have d for any t.
Isktaine,
thank you very much! Uncoupling the equations did the trick.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by