在等式中出现的希腊符号\ PHI是expm(A*t)
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解算器提供的图表就会非常相似。所以,我的代码对于t0=0
来说很好,但是对于任何其他值我的代码出错了。
答案 0 :(得分:3)