フィルターのクリア

solving a differential equation coupling together in matrix and vector form with ode45

1 回表示 (過去 30 日間)
I have two problem:
1) I used two functions for solving a set of equation not in matrix or vector form but like
[x(2);3+x(4)+x(3);x(4);....................]
then [t,x] = ode45(@(t,x) lili(t,x),tspan,x0);
now I need the vector of dx=[x(2) x(4) x(6)]
but it doesnt return this vector.
2) i want to solve equation like this D2y=d2x+cross(m,n)
its clear cross product is in vector form
how could i solve matrix form of differential equation?
especially initial values is a vector
  1 件のコメント
Torsten
Torsten 2018 年 12 月 6 日
1) Unclear what you have done and what your problem is. Please provide the code you are using and possibly the error message you get.
2) ODE45 expects the differential equations to be given in vector format. So convert your equations from matrix form to vector form.
Best wishes
Torsten.

サインインしてコメントする。

採用された回答

roya afshar
roya afshar 2018 年 12 月 7 日
clc
clear
x_1=[1 8 9];
x_2=[2 3 4];
x0=[x_1 x_2].';
tspan = [0 20];
one = 1:3;
two = 4:6;
n=[0 1 2]';
f = @(t,x) [x(two);x(one)+n]
[t, xR] = ode45(f, tspan, x0);
x1 = xR(:,one)
x2 = xR(:,two)
plot(x1,t)
%plot(x2,t)
I have found a solution could any make me sure?
  2 件のコメント
Torsten
Torsten 2018 年 12 月 7 日
You solve
x1'' = x1
x2'' = x2 + 1
x3'' = x3 + 2
with initial conditions
x1(0)=1, x2(0)=8, x3(0)=9, x1'(0)=2, x2'(0)=3, x3'(0)=4
and plot x1, x2 and x3 in plot 1 and x1', x2' and x3' in plot 2.
Is it that what you wanted to achieve ?
roya afshar
roya afshar 2018 年 12 月 8 日
yes exactly.
thank you so much

サインインしてコメントする。

その他の回答 (1 件)

roya afshar
roya afshar 2018 年 12 月 6 日
I have solved 3 second order of differential equations by ode45 and there is no error. as a example:
D2x=x+z+Dx+Dy
D2Y=Dx+z
D2z=Dz+Dx+y
more complicated than above and its nonlinear. and my codes:
function dy=roya(t,y)
dy=[y(2);y(1)+y(5)+y(2)+y(4);y(4);y(2)+y(5);y(6):y(6)+y(2)+y(3)];
end
y0=[0 0 0 0 0 0];
tspan = [0 5];
[t,y] = ode45(@(t,y) roya(t,y),tspan,y0);
now I need vector[y(1) y(3) y(5)] , [y(2) y(4) y(6)]
.........................................................
after solving above I wand to use [y(1) y(3) y(5)] this vector in another differential equation like:
D2m=D2y+cross(a,b)+D1y;
how could I define initial value for this equation
output is a 3by1 vecor?and a,b are 3by3 matrix
  3 件のコメント
roya afshar
roya afshar 2018 年 12 月 7 日
the problem is initial value of Dm and m. how could I define initial value for them as a vector? if I solve all of them together I have to define initial value like this?y0=[0 0 0 0 0 0 [1 2 3] [2 3 4]];
a is a 3by1
b 1by3 vector
but if I solve them together and there were no problem still I need to call some of states as an input of kalman filter.
roya afshar
roya afshar 2018 年 12 月 7 日
編集済み: roya afshar 2018 年 12 月 7 日
clc
clear
y0=[10 5 3];
y1=[1 2 3];
tspan = [0 5];
[t,y] = ode45(@(t,y) bhr(t,y),tspan,[y0 y1]);
function dy = bhr(t,y)
n=[0 1 2];
dy =[y(2);n+y(1)];
end
simple example of what i am looking for is above.
I am trying solve second order deffirential equation in vector form.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by