# Solving differential equation in simulink

21 次查看（过去 30 天）

显示 更早的评论

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 个评论

hosein Javan
2020-8-10

Muhammad Saqlain Haider
2020-8-10

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
2020-8-11

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
2020-8-13

hosein Javan
2020-8-13

Muhammad Saqlain Haider
2020-8-13

hosein Javan
2020-8-13

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
2020-8-13

Sam Chak
2020-8-13

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
2020-8-13

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
2020-8-13

Sam Chak
2020-8-13

编辑：Sam Chak
2020-8-13

Muhammad Saqlain Haider
2020-8-13

Muhammad Saqlain Haider
2020-8-13

Muhammad Saqlain Haider
2020-8-13

hosein Javan
2020-8-13

Muhammad Saqlain Haider
2020-8-14

编辑：Muhammad Saqlain Haider
2020-8-14

@hosein Javan I hope it will work now

hosein Javan
2020-8-14

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
2020-8-14

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

hosein Javan
2020-8-15

Muhammad Saqlain Haider
2020-8-15

hosein Javan
2020-8-16

编辑：hosein Javan
2020-8-16

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
2020-8-16

hosein Javan
2020-8-16

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
2020-8-16

Muhammad Saqlain Haider
2020-8-16

hosein Javan
2020-8-16

Muhammad Saqlain Haider
2020-8-17

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

hosein Javan
2020-8-17

don't mention it brother. please if you are convinced with the answer, hit "accept".

Muhammad Saqlain Haider
2020-8-19

Sam Chak
2020-8-19

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
2020-8-19

Sam Chak
2020-8-19

@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
2020-8-19

Sam Chak
2020-8-19

### 采纳的回答

hosein Javan
2020-8-19

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 个评论

Muhammad Saqlain Haider
2020-8-19

Sam Chak
2020-8-19

Muhammad Saqlain Haider
2020-8-19

hosein Javan
2020-8-19

### 更多回答（0 个）

### 另请参阅

### 类别

### Community Treasure Hunt

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

Start Hunting!**发生错误**

由于页面发生更改，无法完成操作。请重新加载页面以查看其更新后的状态。

您也可以从以下列表中选择网站：

如何获得最佳网站性能

选择中国网站（中文或英文）以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。

美洲

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

欧洲

- 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)

亚太

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