**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# Solving differential equation in simulink

15 views (last 30 days)

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

Muhammad Saqlain Haider
on 10 Aug 2020

Thank you for your responce sir. Much appreciated

qg is output of mode and actually qg is not know but I make it known by thinking that if operating set point of Tin is given then I subtracted this set point from Tin value that is coming after integral then I multiplied it with Rho_q,Va and Ca and divided it with time to make its unit in watts (as is evident from simulink model attached). Now I do not know whether its a rigt way to do or not?

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

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

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
on 13 Aug 2020

Edited: Sam Chak
on 13 Aug 2020

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

Muhammad Saqlain Haider
on 13 Aug 2020

Here is .slx file

hosein Javan
on 13 Aug 2020

of course, I will check it tommorow, best wishes.

Muhammad Saqlain Haider
on 13 Aug 2020

Ok Thank you brother for your help

Muhammad Saqlain Haider
on 14 Aug 2020

Hosein Javan any update please?

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

Sure brother..Appreciate it

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 I hope it will work now

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

As for as this is concerned "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".".

I am doing same, Tin is my output of model and I am feeding it back because in all inputs it is needed. As for as ode is concerned I do not think so there is any error in writing equation in simulink but yes there is something wrong because of which model is not working

Muhammad Saqlain Haider
on 14 Aug 2020

hosein Javan
on 15 Aug 2020

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

Muhammad Saqlain Haider
on 17 Aug 2020

Thank you so much brother @hosein Javan. I really appreciate your quick and wonderful responce.

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

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

### Accepted Answer

hosein Javan
on 19 Aug 2020

hello again. this should look like this:

by clicking on "Tune" an app opens and tries to first linearize the system and then choose the best coefficients.

##### 4 Comments

Muhammad Saqlain Haider
on 19 Aug 2020

Sam Chak
on 19 Aug 2020

Muhammad Saqlain Haider
on 19 Aug 2020

hosein Javan
on 19 Aug 2020

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

- América Latina (Español)
- Canada (English)
- United States (English)

Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)