Solve Semilinear DAE System
该工作流程是求解半线性差异代数方程(DAE)的替代工作流程,仅在还原活性
failed in the standard workflow with the warning message:减少DAE的索引大于1。
。For the standard workflow, see求解差分代数方程(DAE)。
完成步骤1和2求解差分代数方程(DAE)在开始其他步骤之前。然后,在第3步中,如果还原活性
fails, reduce the differential index using还原
。这advantage of还原
是that it reliably reduces semilinear DAEs to ODEs (DAEs of index0
). However, this function is slower and works only on semilinear DAE systems.还原
can fail if the system is not semilinear.
To solve your DAE system, complete these steps.
步骤1.指定方程式和变量
这DAE system of equations is:
Specify independent variables and state variables by usingsyms
。
symsx(t)y(t)t(t)mrg
Specify equations by using the == operator.
eqn1 = m*diff(x(t), 2) == T(t)/r*x(t); eqn2 = m*diff(y(t), 2) == T(t)/r*y(t) - m*g; eqn3 = x(t)^2 + y(t)^2 == r^2; eqns = [eqn1 eqn2 eqn3];
将状态变量放在列矢量中。存储用于参考的原始变量的数量。
vars = [x(t);y(t);t(t)];origvars =长度(vars);
步骤2.减少差分顺序
这differential orderDAE系统的最高差异顺序。要使用MATLAB®解决DAE,必须将差分降低到1
。在这里,第一个方程和第二个方程式具有二阶导数x(t)
和y(t)
。Thus, the differential order is2
。
通过使用将系统减少到一阶系统减少差异排列
。这减少差异排列
功能替代具有新变量的衍生物,例如Dxt(t)
和dyt(t)
。这right side of the expressions ineqns
是0
。
[eqns,vars] =降低差异(eqn,vars)
eqns =
vars =
步骤3.用还原
To reduce the differential index of the DAEs described byeqns
和vars
, 采用还原
。To reduce the index,还原
adds new variables and equations to the system.还原
还返回约束,这是有助于找到初始值以确保所得ODE等于初始DAE的条件。
[ODEs,constraints] = reduceDAEToODE(eqns,vars)
odes=
约束=
Step 4. ODEs to Function Handles for ode15s and ode23t
From the output of还原
,您有一个方程向量odes
和a vector of variables invars
。To useode15s
或者ode23t
,您需要两个函数手柄:一个代表ODE系统的质量矩阵,另一个代表包含质量矩阵方程右侧的向量。这些函数处理是ode系统的等效质量矩阵表示M(t,y(t))y’((t) =f(t,y(t)。
通过使用Massmatrixform
质量矩阵Massm
(M在方程式中)和右侧f
。
[massM,f] = massMatrixForm(ODEs,vars)
massm =
f =
方程式odes
can contain symbolic parameters that are not specified in the vector of variablesvars
。Find these parameters by usingsetdiff
在输出symvar
从odes
和vars
。
podes = symvar(odes);PVARS = SYMVAR(vars);extraparams = setDiff(豆荚,PVARS)
extraParams =
这extra parameters that you need to specify are the massm
, radiusr
和重力常数g
。
ConvertMassm
和f
to function handles usingodeFunction
。将额外符号参数指定为其他输入odeFunction
。
massm = odefunction(Massm,vars,m,r,g);f = odefunction(f,vars,m,r,g);
其余的工作流程纯粹是数值。设置参数值并替换参数值DAEs
和constraints
。
M = 1;r = 1;G = 9.81;odesNumeric = subs(odes);ConstraintSnumeric = subs(约束);
Create the function handle suitable for input toode15s
或者ode23s
。
m = @(t,y)massm(t,y,m,r,g);f = @(t,y)f(t,y,m,r,g);
Step 5. Initial Conditions forode15s
和ode23t
这solvers require initial values for all variables in the function handle. Find initial values that satisfy the equations by using the MATLAB迪克
功能。这迪克
accepts guesses (which might not satisfy the equations) for the initial conditions and tries to find satisfactory initial conditions using those guesses.迪克
can fail, in which case you must manually supply consistent initial values for your problem.
First, check the variables invars
。
vars
vars =
Here,Dxt(t)
是the first derivative ofx(t)
, 等等。有5个变量5
-经过-1
向量。因此,猜测变量及其导数的初始值也必须是5
-经过-1
vectors.
Assume the initial angular displacement of the pendulum is 30° orpi/6
, and the origin of the coordinates is at the suspension point of the pendulum. Given that we used a radiusr
的1
, the initial horizontal positionx(t)
是r*sin(pi/6)
。初始垂直位置y(t)
是-r*cos(pi/6)
。Specify these initial values of the variables in the vectory0est
。
任意将其余变量及其导数的初始值设置为0
。这些不是很好的猜测。但是,它们足以解决这个问题。在您的问题中迪克
errors, then provide better guesses and refer to the迪克
页。
y0est = [r*sin(pi/6);-r*cos(pi/6);0;0;0];YP0est = zeros(5,1);
Create an option set that contains the mass matrixM
系统的数字搜索指定数值公差。
opt = odeset('大量的',m,'RelTol',10.0^(-7),'abstol',10.0^(-7));
找到与ODE系统和代数约束一致的初始值迪克
。这parameter[1,0,0,0,1]
在此功能中,调用修复了第一个和最后一个元素y0est
, so that迪克
does not change them during the numerical search. Here, this fixing is necessary to ensure迪克
找到令人满意的初始条件。
[y0,yp0] = decic(odesNumeric,vars,constraintsnumeric,0,。。。y0est,[1,0,0,0,1],yp0est,opt)
y0 =5×10.5000 -0.8660 -8.4957 0 0
yp0 =5×10 0 0 -4.2479 -2.4525
现在创建一个包含质量矩阵的选项集M
的the system and the vectorYP0
的consistent initial values for the derivatives. You will use this option set when solving the system.
opt = odeset(opt,“初始滑坡”,yp0);
Step 6. Solve an ODE System withode15s
或者ode23t
Solve the system integrating over the time span0
≤t
≤0.5
。Add the grid lines and the legend to the plot. Useode23s
通过更换ode15s
withode23s
。
[TSOL,YSOL] = ODE15S(F,[0,0.5],Y0,OPT);情节(TSOL,YSOL(:,1:ORIGVARS),'-o')fork = 1:origVars S{k} = char(vars(k));endlegend(S,'地点','Best') 网格在
通过设置新值并重新生成功能句柄和初始条件来解决不同参数值的系统。
Setr
to2
和repeat the steps.
r = 2;odesNumeric = subs(odes);ConstraintSnumeric = subs(约束);m = @(t,y)massm(t,y,m,r,g);f = @(t,y)f(t,y,m,r,g);y0est = [r*sin(pi/6);-r*cos(pi/6);0;0;0]; opt = odeset('大量的',m,'RelTol',10.0^(-7),'abstol',10.0^(-7));[y0,yp0] = decic(odesNumeric,vars,constraintsnumeric,0,。。。y0est,[1,0,0,0,1],yp0est,opt); opt = odeset(opt,“初始滑坡”,yp0);
Solve the system for the new parameter value.
[TSOL,YSOL] = ODE15S(F,[0,0.5],Y0,OPT);情节(TSOL,YSOL(:,1:ORIGVARS),'-o')fork = 1:origVars S{k} = char(vars(k));endlegend(S,'地点','Best') 网格在
See Also
不良功能
|迪克
|findDecoupledBlocks
|incidenceMatrix
|Islowindexdae
|Massmatrixform
|odeFunction
|还原活性
|还原
|减少差异排列
|还原品