System of ODE

Hi, I'm very new with Matlab. I have been trying to solve a system of ODE with 100 or even more equations. I know how to solve one ODE or system of ODE (with few equations) with ODE45. Writting more than 100 equations in the function file is very tedious. So I'm thinkg to write the function file in matrix form. For example:
dydt = A * y
Where dydt = [dy1/dt
dy2/dt
......
......
dyn/dt];
A = [a1 a2 a3 ..... ...............an
b1 b2 b3.......bn
.................
.................
n1 n2 n3 ......nn]
y = [y1
y2
..
yn];
(n >= 100)
I have already generated my A matrix. I just would like to know how can I write the code for implement "dydt = A * y" in the function file.
I really appreacite for any kind of assistance.
Thanks.

Answers (1)

Matt Tearle
Matt Tearle on 5 Mar 2011
You already have the code: dy = A*y. Given how simple it is, you don't even need to write a function file -- you could just use an anonymous function handle:
odefun = @(t,y) A*y;
[t,y] = ode45(odefun,t0,y0);
But if your ODE is linear, why do you even need to use ode45? A linear system has an analytic solution. You could possibly use eig and/or expm to work out whatever you need.

1 Comment

jahid
jahid on 9 Mar 2011
Thanks a lot. I was pretty close to the solution.
Now, I'm trying to code the following equation:
dy = A*y* y(1); % y(1) is the first element of the y matrix. These makes the system non-linear so I thought I moght use ODE45.

Sign in to comment.

Tags

Asked:

on 5 Mar 2011

Community Treasure Hunt

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

Start Hunting!