필터 지우기
필터 지우기

ODE45 WITH MATRIX V AND TIME

조회 수: 1 (최근 30일)
rami
rami 2012년 7월 19일
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
Walter Roberson 2012년 7월 19일
Instead of using global, parameterize your function. Then it becomes easy to loop over an array of values.
  댓글 수: 5
rami
rami 2012년 7월 20일
편집: Walter Roberson 2012년 7월 20일
however this all program:
function xprime = tdofssfun(t, x, a, b, k, x0, v)
xprime = (a-b*k)*x - (a-b*k)*[ v;0;0]
end
a=[0 1 0;0 0 1; -1.9*10^5 -2*10^5 -2.4*10^5];
% define the input matrix, b
b=[0 ;0 ;6*10^5];
% define the output matrix for transient response, c, displacements only
c = [1 0 0];
k=[ 110 16 0];
v=[ 0 0.0245 0.0736 0.1471 0.2452 0.3678 0.5149 0.6865 0.8827 1.1034 1.3486 1.6183 1.9125 2.2313 2.5745 2.9423 3.3346 3.7515 4.1928 4.6587 5.1491 5.6640 6.2034 6.7674 7.3558 7.9688 8.6063 9.2684 9.9304 10.5679 11.1809 11.7693 12.3333 12.8727 13.3876 13.8780 14.3439 14.7852 15.2021 15.5944 15.9622 16.3072 16.6504 16.9692 17.2634 17.5331 17.7783 17.9990 18.1952 18.3668 18.5139 18.6365 18.7346 18.8081 18.8572 18.8817 18.8817];
tspan = [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57];
x0 = [0 0 0]'; % initial condition vector, note transpose
options = []; % no options specified for ode45 command
for N = 1 : length(v) - 1
[t{N}, x{N}] = ode45(@(t,x) tdofssfun(t, x, a, b, k, x0, v(N)), tspan(N:N+1), x0, options);
end
figure(1)
plot(t{N}, x{N}(:,1))
Walter Roberson
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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by