ODE45 WITH MATRIX V AND TIME
1 view (last 30 days)
Show older comments
Hi
I have a function
function xprime = tdofssfun(t,x)
global a b u k x0 T v1
xprime = (a-b*k)*x -(a-b*k)*[ v1;0;0];
end
THEN
[t,x] = ode45('tdofssfun',tspan,x0,options);
and I want solve the equation where a 3*3 matrix, b 3*1 matrix k1*3 matrix
In general i can solve this equation if v1 is constant or has function with time
but the problem I have matrix of value for v1 and evrey value calculating at on time so i want to solve this equation
as example
v1=[0.2 0.5 0.6 0.9]
with time
t=[0.5 1 1.5 2]
Thx
0 Comments
Answers (1)
Walter Roberson
on 19 Jul 2012
Instead of using global, parameterize your function. Then it becomes easy to loop over an array of values.
5 Comments
Walter Roberson
on 20 Jul 2012
I would need to run the code to test (which I cannot do this week), but what I suspect you want as output is
tvals = vertcat(t{:});
xvals = vertcat(x{:});
x1vals = xvals(:,1);
plot(tvals, xvals);
See Also
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!