Solving nonlinear system of ode in Simulink

31 views (last 30 days)
Tom
Tom on 14 Sep 2021
Commented: Tom on 15 Sep 2021
I am trying to solve a system of nonlinear equations of motion in Simulink, where
x = [x1...x7] is the system state with the derivatives xdot = [x1dot...x7dot] and xdotdot = [x1dotdot...x7dotdot],
p = [p1...pn] are parameters (partly non constant) and
u = [u1...u3] is the system input.
All 7 equations are nonlinear, e.g.
p2*x2dotdot - p3*x3dotdot + p4*x4dotdot + p5*x4dot*x5dot - p6*x5 + p7 + u1 = 0;
As a result of this form, the second derivatives depend on another. This leads to a set of equations
x1dotdot = f1(p,u,x,xdot)
x2dotdot = f2(p,u,x,xdot,x3dotdot,x4dotdot,x5dotdot)
x3dotdot = f3(p,u,x,xdot,x2dotdot,x4dotdot,x5dotdot)
x4dotdot = f4(p,u,x,xdot,x2dotdot,x3dotdot,x5dotdot)
...
What I have tried so far is implementing the equations in a simulink model without changing their form. By adding unit delays I solved the equations based on the previous xdotdot.
Another way I tried was by solving the equations for x and xdot using the solve function to get a system of the form xdotdot = f(p,u,x,xdot). Based on this, I tried to change the system to a first order system by expanding x to [x, xdot].
However, all of these tries have lead to bad results (values getting very large + stepsize errors).
How should I go about solving these equations where the derivatives depend on another?

Answers (1)

Paul
Paul on 14 Sep 2021
The best way IMO is to get the equations in the form xdotdot = f(p,u,x,xdot), which you already did. But what did you mean by "expanding x to [x, xdot]."? Once you have the equations in the desired form, they are implemented using either two Integrator blocks in series to integrate from xdotdot to xdot and from xdot to x. The integrator outputs, xdot and x respectively, feed back into the calculation of xdotdot. Or, instead of two integrators, one can use an Integrator, Second Order block.
  5 Comments
Paul
Paul on 14 Sep 2021
You should be able to express the original equations in the implicit form g(xdotdot,xdot,x,u,p) = 0. In this case, you can use an Algebraic Constraint block to solve xdotdot and then integrate to xdot and x. This approach is a valid way to solve the problem, but not preferred. In parallel, you can implement the explicit equation for f(xdot,x,u,p) and verify that it yields the same output of the Algebraic Constraint. If it doesn't, it means that the g() and xdotdot - f() are not consistent with each other.
As an example, the block diagram below implements the equations A*xdotdot = -xdot - x + u, wiith u = 1 with A = [1 0.5; 0.1 1] The upper part of the diagram uses the Algebraic Constraint to solve for xdotdot and integrate the differential equaution, while the bottom shows that the explicit solution for xdotdot = inv(A)*(u - xdot - x) matches the output of the Algebraic Constraint.
Tom
Tom on 15 Sep 2021
Thanks! I'll try this out and report my findings when I'm done

Sign in to comment.

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!