ODE45 WITH MATRIX V AND TIME
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2012-7-19
Instead of using global, parameterize your function. Then it becomes easy to loop over an array of values.
5 个评论
Walter Roberson
2012-7-20
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!