これはプログラミングと数学の両方を含む質問です。だから、で記述された線形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)
グラフに示された曲線が初期値で始まらないので、解決策は1
です。しかし、形状は、それはプロットはMATLABのODEソルバによって与えたから非常に似ています:
をしかし、私はその後、t0=0
設定した場合、プロットは私のコードで与え、MATLABでソルバーそれはお互いにexacly等しいです。だから、私のコードそれはt0=0
のための罰金ですが、他の値と私のコードは間違って行く。
'c_0 = invhom * x_0'行のt0でinvhomを評価するのを忘れた – gustavoreche
@gustavoreche良いキャッチ!回答が更新されました。 – TroyHaskin