主要内容

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:

m d 2 x d t 2 = T ( t ) x ( t ) r m d 2 y d t 2 = T ( t ) y ( t ) r - m g x ( t ) 2 + y ( t ) 2 = r 2

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 ineqns0

[eqns,vars] =降低差异(eqn,vars)
eqns =

( m t Dxt ( t ) - T ( t ) x ( t ) r g m + m t Dyt ( t ) - T ( t ) y ( t ) r - r 2 + x ( t ) 2 + y ( t ) 2 Dxt ( t ) - t x ( t ) Dyt ( t ) - t y ( t ) )

vars =

( x ( t ) y ( t ) T ( t ) Dxt ( t ) Dyt ( t ) )

步骤3.用还原

To reduce the differential index of the DAEs described byeqnsvars, 采用还原。To reduce the index,还原adds new variables and equations to the system.还原还返回约束,这是有助于找到初始值以确保所得ODE等于初始DAE的条件。

[ODEs,constraints] = reduceDAEToODE(eqns,vars)
odes=

( Dxt ( t ) - t x ( t ) Dyt ( t ) - t y ( t ) m t Dxt ( t ) - T ( t ) x ( t ) r m t Dyt ( t ) - T ( t ) y ( t ) - g m r r - 4 T ( t ) y ( t ) - 2 g m r t y ( t ) - 2 x ( t ) 2 + 2 y ( t ) 2 t T ( t ) - 4 T ( t ) x ( t ) t x ( t ) - 4 m r Dxt ( t ) t Dxt ( t ) - 4 m r Dyt ( t ) t Dyt ( t ) )

约束=

( - 2 m r Dxt ( t ) 2 - 2 m r Dyt ( t ) 2 - 2 T ( t ) x ( t ) 2 - 2 T ( t ) y ( t ) 2 + 2 g m r y ( t ) r 2 - x ( t ) 2 - y ( t ) 2 2 Dxt ( t ) x ( t ) + 2 Dyt ( t ) y ( t ) )

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 =

( - 1 0 0 0 0 0 - 1 0 0 0 0 0 0 m 0 0 0 0 0 m - 4 T ( t ) x ( t ) 2 g m r - 4 T ( t ) y ( t ) - 2 x ( t ) 2 - 2 y ( t ) 2 - 4 m r Dxt ( t ) - 4 m r Dyt ( t ) )

f =

( - Dxt ( t ) - Dyt ( t ) T ( t ) x ( t ) r T ( t ) y ( t ) - g m r r 0 )

方程式odescan contain symbolic parameters that are not specified in the vector of variablesvars。Find these parameters by usingsetdiff在输出symvarodesvars

podes = symvar(odes);PVARS = SYMVAR(vars);extraparams = setDiff(豆荚,PVARS)
extraParams =
                  
                   
                    
                     
                      (
                     
                      
                       
                        
                         
                          g
                        
                       
                       
                        
                         
                          m
                        
                       
                       
                        
                         
                          r
                        
                       
                      
                     
                     
                      )
                    
                   
                  

这extra parameters that you need to specify are the massm, radiusr和重力常数g

ConvertMassmfto function handles usingodeFunction。将额外符号参数指定为其他输入odeFunction

massm = odefunction(Massm,vars,m,r,g);f = odefunction(f,vars,m,r,g);

其余的工作流程纯粹是数值。设置参数值并替换参数值DAEsconstraints

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 forode15sode23t

这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 =

( x ( t ) y ( t ) T ( t ) Dxt ( t ) Dyt ( t ) )

Here,Dxt(t)是the first derivative ofx(t), 等等。有5个变量5-经过-1向量。因此,猜测变量及其导数的初始值也必须是5-经过-1vectors.

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 radiusr1, 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 span0t0.5。Add the grid lines and the legend to the plot. Useode23s通过更换ode15swithode23s

[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') 网格

Figure contains an axes object. The axes object contains 3 objects of type line. These objects represent x(t), y(t), T(t).

通过设置新值并重新生成功能句柄和初始条件来解决不同参数值的系统。

Setrto2和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') 网格

Figure contains an axes object. The axes object contains 3 objects of type line. These objects represent x(t), y(t), T(t).

See Also

||||||||||

相关话题