Solving differential equation in simulink
Show older comments
Hello Everyone
I am solving a differential equation (attached) of greenhouse energy balance on SIMULINK which has basically two unknowns (Tin and qg). One of them (qg) is model output and other (Tin) is also not know from any means. Now I have to calculate both of these parameters from this differential equation. The only thing that I know is the 6 factors on rightside of the equation but all of them are dependent on Tin and there is a operating set point for temperature is given as 20 for day and 16 for night for greenhouse. Can someone help me to solve this equation?
My simulink model is also attached.Plzzzz guide me
44 Comments
hosein Javan
on 10 Aug 2020
if you are solving an ode then you have only one differentiable variable. if that is Tin, then qg is not unknown and in your simulink model it is evident that it is dependent on Tin. if the other variables are dependant on Tin, it doesnt matter. just use fcn to define the dependancy on Tin. your model is correct what's the problem?
Muhammad Saqlain Haider
on 10 Aug 2020
hosein Javan
on 11 Aug 2020
hello again. you're welcome.
your method for ode simulation is correct. in general when you want to solve "xdot=f(x,u)", you must first calculate f(x,u) then using an integrator, feed it back to your f(x,u). unless your formulation is miscalculated, the rest does not have a problem.
Muhammad Saqlain Haider
on 13 Aug 2020
hosein Javan
on 13 Aug 2020
don't mention it. this part is not relevant to your equation. is this another equation? why is time constant "time=1"? I can't say anything for this section. you need to check the other part of the simulation where other quantities like q_lamp, q_cond ,... are defined.

Muhammad Saqlain Haider
on 13 Aug 2020
hosein Javan
on 13 Aug 2020
you are implementing this equation to calculate qg.
I assume you want to control Tin by varying qg. and the proportional factor is:
be sure that it is correct.
about discrete integrator, no it does not make any difference normally.
Muhammad Saqlain Haider
on 13 Aug 2020
Sam Chak
on 13 Aug 2020
The model can be written in a compact form as:
If
is designed as follows
then the closed-loop system becomes
Thus, at equilibrium,
,
hosein Javan
on 13 Aug 2020
can you show an image of outside of this subsystem? the problem might be because of that.
the system is not stable. use a PI controller instead of rho_a*V_a*C_a after temperature error. double click on PID controller and hit "Tune". it will provide you kP and kI automatically,
hosein Javan
on 13 Aug 2020
Sam Chak . The math is correct but in control case, Q_disturbance might not be directly measurable or estimated. it is just a model I suppose.
Thanks hosein Javan. I understand that. I boldly proposed that to Muhammad Saqlain Haider because he claimed that the six q terms, which are lumped as
, are known (which I interpreted it as measurable). The ideal case. Otherwise, in the non-ideal case, if
is bounded and not measurable, then the PI controller as you suggested should do the job.
hosein Javan
on 13 Aug 2020
Sam Chak thanks Mr.Chak. I see.
Muhammad Saqlain Haider
on 13 Aug 2020
Muhammad Saqlain Haider
on 13 Aug 2020
Muhammad Saqlain Haider
on 13 Aug 2020
hosein Javan
on 13 Aug 2020
don't mention it Mr.Haider. unfortunately I don't know from these picures. can you upload your .slx file?
Muhammad Saqlain Haider
on 13 Aug 2020
hosein Javan
on 13 Aug 2020
of course, I will check it tommorow, best wishes.
Muhammad Saqlain Haider
on 13 Aug 2020
Muhammad Saqlain Haider
on 14 Aug 2020
hosein Javan
on 14 Aug 2020
sorry I was busy today. I'll let you know a few hours later.
Muhammad Saqlain Haider
on 14 Aug 2020
hosein Javan
on 14 Aug 2020
sorry, I'm using matlab 2016a. can you export it to this older version?
Muhammad Saqlain Haider
on 14 Aug 2020
Edited: Muhammad Saqlain Haider
on 14 Aug 2020
hosein Javan
on 14 Aug 2020
yes it worked now. the model is too complicated to comprehend, I suggest first try to simplify the model in this way:
the model can be represented by "n" ode in the form of "Xdot = f(X,U)". so create a one subsystem that has input "X,U" and outputs "f(X,U)". then feed it to an integrator and then feed it back to "X".
also, some "from workspace" blocks are undefined. I suggest instead of these, use "constant" with pre-defined values. I saw that some of them were tout. how is it that tout is needed for a simulation? use "clock" if necessary however in most cases it is unneeded.
Once you know that everything that is related to model is done, create a subsystem that defines your system. this subsystem has input "U" and outputs "X".
right now the model is ready for simulation. provide some arbitrary inputs for "U" and check if the system response "X" is expected, and no error like infinite states apper. note that the "X" must be stable at equilibrium. if not the system is ill-defined. for now just the model is defined. please don't add any extra feedback closed-loop controllers, and only check its response.
allrigth, when system check done, it is time for control, but for now, check only the system. I suggest you once again write all equations on paper and create a new file based on above steps. once you are done with all that please let me know.
Muhammad Saqlain Haider
on 14 Aug 2020
Muhammad Saqlain Haider
on 14 Aug 2020
hosein Javan
on 15 Aug 2020
yes I know. I just meant that the model is confusing for a lot of line signals. that's why I suggested at first try to simplify the model. you can also use "Goto" and "From" blocks to reduce its complexity. please test the model once without the feedback controller to ensure that the error is not due to system definition. good luck.
Muhammad Saqlain Haider
on 15 Aug 2020
hosein Javan
on 16 Aug 2020
Edited: hosein Javan
on 16 Aug 2020
don't mention it my brother. division by zeros normally should not happen. probably some algebraic equations are defined in such a way that some variable is divided by a state variable at initial condition which is zero. please first check that this signal is defined correctly, if it is correct try to:
- if there is way to define this equation in another way that does not require division by zero, do it. for example if the equation is y1=x2/x1, and we already know that x1=1/x3, then we can rewrite y1=x2*x3.
- some algebric equations have a limit at zero. for example limit(sin(x)/x)=1. if there is any equations that have limit, try to add a switch that when the signal is zero, produce this pre-calculated limit.
- change initial condition in a way that division by zeros does not happen. for example if y1(t)=x2(t)/x1(t) and x1(0)~=0, then division by zeros does not happen.
- if none of these methods are incapable, we can use saturate the value of denominator dynamically to "eps", this way a very large but not inf occurs. however it is the least we can do and it is strongly recommended to avoid this method, because it might lead to unwanted phenomena like many zero-crossings and instability of the system due to very large signal.
Muhammad Saqlain Haider
on 16 Aug 2020
hosein Javan
on 16 Aug 2020
suppose that simuliink measures time in terms of seconds. then it means that if state variable x(t) is in terms of meter then the state variable v(t)=dx(t)/dt is in terms of meter per seconds at any seconds.
now imagine that we don't even know that simulink measures time in seconds, for example we might think that simulink measures in hours. then if state x(t) is distance in terms of meter, this time, v(t)=x(t)/t is speed in terms of meter/hours.
so we see that only units that are time-based change by a scale. now for example here wind speed is in terms of a distance unit like meter or kilometer or miles,... per hours.
so in a conclusion, if we suppose time is in terms of hours, only the time depandant units change by a factor that can be easily retreived, the other units don't change.
Muhammad Saqlain Haider
on 16 Aug 2020
Muhammad Saqlain Haider
on 16 Aug 2020
hosein Javan
on 16 Aug 2020
Yes, Exactly. Just turn every thing that you thought was seconds to hours. Only units that deal with time like speed. But the other units that are not a "time-rate of something" like heat and temperature are no time-depandant units. Remember that some quantities have time hidden in them. like electric current which is time rate of charge flowing.
Muhammad Saqlain Haider
on 17 Aug 2020
hosein Javan
on 17 Aug 2020
don't mention it brother. please if you are convinced with the answer, hit "accept".
Muhammad Saqlain Haider
on 19 Aug 2020
Sam Chak
on 19 Aug 2020
Hi Muhammad Saqlain Haider,
Have you successfully run and stabilize the system with the designed controller without any singularity (division-by-zero) error message?
Muhammad Saqlain Haider
on 19 Aug 2020
Sam Chak
on 19 Aug 2020
@Muhammad Saqlain Haider. The disturbance blocks in the images are "External disturbances", are external elements in the process that perturb the responses of the system states. External disturbance can be a constant or time-varying, or a mixed of both in different periods of time.
External disturbance such as gravity (gravitational force) is generally a constant (for land dwellers) and is independent of the system states.
External disturbance such as air drag (aerodynamic force due interaction with external air particles) depends on the system's velocity (one of the states in a motion system).
Muhammad Saqlain Haider
on 19 Aug 2020
Sam Chak
on 19 Aug 2020
Hi Muhammad Saqlain Haider, I didn't study your system dynamics in the Simulink model. Perhaps Dr. hosein Javan can provide constructive insights on this matter because he has previously viewed and commented on your Simulink slx file.
Accepted Answer
More Answers (0)
Categories
Find more on PID Controller Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




