Differntial equations and Initial conditions

1. What are the main considerations for selecting initial conditions for solving dynamics equations using Matlab Simulink. For instance, setting the initial conditions in the continuous state block or integral block?
2. Is it possible to use a mathematcal expression or relation instead of a number as the initial condition in the integral block of Simulink?

 Accepted Answer

Paul
Paul on 28 Mar 2021
  1. The initial conditions are set to represent the initial conditions of the system to be simulated. What other considerations might there be?
  2. Yes. Any expression can be used that returns a value that is consistent with the requirements for the initial condition of the block in question.

12 Comments

Thank you for the reply. Now I have a system of differential equations that is about 32 set of differential equations. I have been able to use a single integrator for the simulink implementation. I have initial conditions that are mathematical expressions, which are derived from the steady state equillibrium conditions of each sets of the differential equations. My challenege is that I dont know how to insert each mathematical expressions of the initial conditions into the integral block. I have attached the intgeral block with some sample sets of initial condition which are constants.However I want expressions as attached also as the initial condition. The initial conditions are the calculated by equating the each differential equation to zero and make the desired state, the subject of the formula. Then it is the initial condition valeu at the equilibrium state. How do i realize such expression in the attached simulink matlab function i used to implement the system in the integral block.
May be there is a way to impelement Initial condition of large mathematical expression within the matlab function blokc used to solve the differential equations?
Thank you
If you have a function in an m-file that computes the initial conditions, i.e., returns a 32-element vector, based on paramters you specify or defined in the base workspace, you can just enter that function in the Inital Condiiton paramter (where you have the 1's and 30'). More generally, you can enter any Matlab expression into the Initial Conditon that results in 32-element vector. Alternatively, you can specifcy the Initial Condition Source as External, and then compute the initial conditions as a 32-element vector output of another block in your model, and connect that block's output to the initial condition input to the integrator.
@Paul thank you. Let me try to implement the 4 options suggested. Although this is my first time of reading or coming across these options. I will try to implement and let you know how it goes please. Or if if you could help with a demonstration using a simple m-file and integral block to demonstrate I would appreciate.
Thank you
@Paul here are some of the mathematical expressions for my inital conditions.
All the 32 equations have different initial condotion expressions. Now how to calculate each one in an m-file and then import to the integrator block is the challenge for me. I would be glad if you could give suggestions. Based on your opinion, seems to me that your method is applicable to the case of one mathematcial expression?
Any Matlab expression, which includes function calls, and be used as the Initial Condition, as long as the expression results in the the 32-element vector of initial conditions. So you can develop one function (that calls other as necessary) that returns a 32-element vector of initial conditions and make that function call the parameter in the Initial Condition in the dialog of the Integrator block. Or you can put 32 function calls that each return a scalar into an array as the Initial Condition parameter, just like would be done at the command line
[func1(arg1,arg2,etc) func2(arg1,arg2,etc) etc func32(arg1,arg2,etc)]
Thank @Paul I will implement it. each initial condition has its own unique mathematical expression. I think, if i write a m-file script that calculate each. Then i can use 'from workspace block' to import the initial conditions to the Integrator block using the external initial condition of the integrator to connect with the 'from workspace blcok'. I think it should work?
That approach can work, seems like overkill. Sounds like you have a script that results in a 32-element vector of initial conditions in the base workspace. Let's call that vector x0. Why not just set the Integrator "Initial condition source" to "internal" and put x0 in the field for "Initial condition:"
@Paul Great!! Thank you for the insight. I will try all and adopt the most efficient one.
Can you please let me know how you would have writen different equations to be in vector form at the end. I feel may be by indexing each result of the mathematical expressions as may be X(1)...........X(32) using assignment?
Let X0 be the vector of initial conditions. One approach would be to compute
X0(1) = ....
X0(2) = ....
i.e., fill in each element X0 with the initial condition cacualtion in the base workspace. Then X0 is the Initial Condition parameter in the Integrator block.
Great! perfect!!! thank you so much

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products

Release

R2018a

Asked:

on 28 Mar 2021

Commented:

on 31 Mar 2021

Community Treasure Hunt

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

Start Hunting!