Simulink - How to create a conditional "if" block

13 views (last 30 days)
Dear experts, @Stephen23
I have a simulink model, in this model there are two senarios. (heating and cooling)
1- heating: The 1st eq applies when the tempreature increases from 50 to 70 C
2- cooling: The 2nd eq is applied when the tempreature decreases from 70 to 50 C
So, when the tempreature goes from 50 to 70, I use the 1st eq. Until the tempreature reaches >=70 and start runing the cooling unit and using the 2nd eq. Until the tempreature reaches <=50. and so on.
the initial condition is the tempreature is 50 and start heating.
How can I create blocks for this purpose in simulink.
Thank you.
  2 Comments
Umar
Umar on 21 Jun 2024
Hi Ahmad, To implement speed-dependent equations in Simulink, you can use the "Switch" block along with a combination of "Relational Operator" blocks to compare the speed values and switch between equations accordingly.
Here's a high-level overview of how you can achieve this:
Use a "Relational Operator" block to compare the speed signal with the threshold values (e.g., 50 and 70 rpm). Connect the output of the "Relational Operator" blocks to a "Switch" block to select between the two equations. Implement your equations in separate subsystems or blocks and connect them to the "Switch" block based on the condition. By setting up the conditions and connecting the blocks appropriately, you can create a dynamic system in Simulink that switches between equations based on the speed thresholds specified. This approach allows for a flexible and efficient way to model speed-dependent behavior in your simulation.
Ahmad Al-Issa
Ahmad Al-Issa on 21 Jun 2024
Hi Umar, @Umar
Did you notice that many values located in both cases ? like (51, 52, ........69).
for the same value 55 rpm for example I use 1st eq and and then I use 2nd eq.

Sign in to comment.

Accepted Answer

Paul
Paul on 21 Jun 2024
Perhaps you can use a Relay block to model the desired behavior based on the heating/cooling analogy. The output of the Relay can be used to drive a Switch the controls which equation is used, or a pair of Enabled subsytems. Probably other options as well.
  9 Comments
Ahmad Al-Issa
Ahmad Al-Issa on 22 Jun 2024
Edited: Ahmad Al-Issa on 22 Jun 2024
Thanks Umar for your contribution.
Umar
Umar on 23 Jun 2024
No problem Ahmad, as a team working together, you did achieve your goal. Paul was really helpful throughout this process. Kudos to Paul for his efforts.

Sign in to comment.

More Answers (1)

Sam Chak
Sam Chak on 21 Jun 2024
Firstly, could you determine the rate of change of speed (referred to as "acceleration" in physics)? This information is necessary to ascertain whether the speed is increasing from 50 rpm to 70 rpm or decreasing from 70 rpm to 50 rpm, and to apply the corresponding equation.
If your model does not directly measure acceleration, you may need to estimate it using mathematical functions or Simulink blocks. If you have a specific mathematical function, please provide it.
Strictly speaking, only the sign of acceleration is needed. If acceleration is positive, Equation #1 should be applied; if negative, Equation #2.
There are two additional issues to address:
  1. What happens if the speed remains constant at any value between 50 rpm and 70 rpm (e.g., 60 rpm) at the initial simulation? Is there a third equation for this scenario?
  2. If the speed increases linearly from 50 rpm and Equation #1 is applied, but then decreases from 60 rpm onwards without reaching 70 rpm, should Equation #1 or Equation #2 be used?
  4 Comments
Ahmad Al-Issa
Ahmad Al-Issa on 21 Jun 2024
To your question (For instance, if the speed fluctuates between 55 rpm and 65 rpm (not yet drop below 50 rpm and not yet rise above 70 rpm), should Equation #1 or Equation #2 be used?)
Please just look at the figure I uploaded. If the speed fluctuates in the upward curve so I used the first equation. If it fluctuates in downward curves I will use the second equation.
Because I assume from time = 0 that the speed value is 50 so I will use the first equation. And I'll wait until I get 70 and start using the second equation.
Just imagine cooling or heating something. When the temperature reaches 70 I turn on the cooling until it reaches 50 and then turn on the heating until it reaches 70 and so on.
assume the tempreature is 50 at t = 0.
Ahmad Al-Issa
Ahmad Al-Issa on 21 Jun 2024
Edited: Ahmad Al-Issa on 21 Jun 2024
Hello @Sam Chak
I change the text of my question, please look on it again.
yes you are right for this (I have a feeling that your switching logic must maintain a persistent memory of which Equation is being used in the "existing state" when the speed fluctuates between 55 rpm and 65 rpm.)

Sign in to comment.

Categories

Find more on Two-Phase Fluid Library in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!