How can I pas a matrix to function handle which is going to be used in ode45 solver?
Show older comments
Hi, Im beginner in Matlab and I need to solve system of differential equations. I was thinking about using ode45 solver. I made a script which produces matrix of parameters which i would like to use in my system of equations: A = [a b c, d e f, g h i]; I would like my system to look like that: dy(1)= a*y(1)+b*y(2)+c*y(3) dy(2)= d*y(1)+e*y(2)+f*y(3) dy(3)= g*y(1)+h*y(2)+i*y(3)
And this system has to be made in function: function dy=example(t,y) and then used in ode45: [X,Y]=ode45(@example,xspan,ynot);
However the A matrix is counted in a script. Is there a chance to pass the A-matrix to function example and run it in ode45 with this parameter?
Please help
Answers (1)
Andrei Bobrov
on 30 Jul 2012
A = [a b c, d e f, g h i];
example = @(t,y)A*y;
[X,Y]=ode45(example,xspan,ynot);
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!