2016-03-27 6 views
0

これはプログラミングと数学の両方を含む質問です。だから、systemで記述された線形ODEのシステムの一般的な解を計算するコードを書くことを試みています。数式は、それは、上に示しています:方程式にappersギリシャのシンボルの\ PHIは問題がODEのソリューションの私のプロットは、それはあなたのように、よく見ていないということですexpm(A*t)間違った結果を与える線形ODEの解を計算する簡単なスクリプト

clear all 

A=[-2]; %system matrix 

t0=1; %initial time of simulation 

tf=2; %final time of simulation 

syms t x_0 

x0=x_0; 

hom=expm(A*t); %hom means "homogeneous solution" 

hom_initialcond=hom*x0;%this is the homogeneous solution multiplied by the initial conditon 

invhom=inv(hom); %this is the inverse of the greek letter at which, multiplied by the input of the system, composes the integrand of the integral 

g=5*cos(2*t); %system input 

integrand=invhom*g; %computation of the integrand 

integral=int(integrand,t0,t); %computation of the definite integral from t0 to t, as shown by the math formula 

partsol=hom*integral; %this is the particular solution 

gen_sol=partsol+hom_initialcond %this is the general solution 

x_0=1; %this is the initial condition 

t=linspace(t0,tf); %vector of time from t0 to tf 

y=double(subs(gen_sol)); %here I am evaluating my symbolic expression 

plot(t,y) 

あるgeneral solution

plot

グラフに示された曲線が初期値で始まらないので、解決策は1です。しかし、形状は、それはプロットはMATLABのODEソルバによって与えたから非常に似ています: enter image description here

をしかし、私はその後、t0=0設定した場合、プロットは私のコードで与え、MATLABでソルバーそれはお互いにexacly等しいです。だから、私のコードそれはt0=0のための罰金ですが、他の値と私のコードは間違って行く。

答えて

3

基本行列の点で一般的な解決策は、しばしば

Equation giving the solution of an ODE system with an initial condition vector for linear, constant coefficient problems

として見

Equation giving the solution of an ODE system with an arbitrary initial condition vector

以上であるが、最初の時間は、多くの場合ゼロであると解釈されるので、逆は、ゼロでの線形定数係数問題(すなわち、expm(zeros(n)) == eye(n))のための同一性であり、cベクトルはtと等価であるため、省略されることが多い彼は初期状態ベクトルです。この

syms t x_0 c_0 
hom    = expm(A*t)    ; 
invhom   = inv(hom)     ; 
invhom_0  = subs(invhom,t,sym(t0)) ; 
c_0    = invhom_0 * x_0   ; 
hom_initialcond = hom * c_0    ; 

にあなたのシンボリック宣言近くの周りの線の一部を交換

は非ゼロ初期時の正しいソリューションを提供する必要があります。

+0

'c_0 = invhom * x_0'行のt0でinvhomを評価するのを忘れた – gustavoreche

+0

@gustavoreche良いキャッチ!回答が更新されました。 – TroyHaskin

関連する問題