ODE45 WITH MATRIX V AND TIME
古いコメントを表示
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
回答 (1 件)
Walter Roberson
2012 年 7 月 19 日
1 投票
Instead of using global, parameterize your function. Then it becomes easy to loop over an array of values.
5 件のコメント
rami
2012 年 7 月 19 日
Walter Roberson
2012 年 7 月 19 日
編集済み: Walter Roberson
2012 年 7 月 19 日
function xprime = tdofssfun(t, x, a, b, u, k, x0, T, v)
xprime = (a-b*k)*x - (a-b*k)*[ v;0;0];
end
for N = 1 : length(v1) - 1
[t{N}, x{N}] = ode45(@(t,x) tdofssfun(t, x, a, b, u, k, x0, T, v1(N)), tspan(N:N+1), x0, options);
end
You should also be considering optimization by pre-calculating common expressions.
rami
2012 年 7 月 20 日
編集済み: Walter Roberson
2012 年 7 月 20 日
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);
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!