# Simulation of First Order System (Matlab & Simulink)

Yesterday, I tried to find constants $k_1$ and $k_2$ for the following system:

$$\frac{\mathrm d RH}{\mathrm dt}=k_1+k_2(RH_{ext}-RH).$$

Now, I have some first computations for $k_1$ and $k_2$ and would like to test how good a simulation with these parameters works. I think I could also write this as state space model:

$$\dot{x}=-k_2x+\left[\begin{matrix} k_1 & k_2\end{matrix}\right]\left[ \begin{matrix} u_1 \\ u_2\end{matrix} \right],$$

$$y = x,$$

where $x = RH$, $u_1=1$ ($const.$) and $u_2=RH_{ext}$. I have measurement data for $RH_{ext}$ in Matlab (vector), a time vector $t$ with the same length and would like to do a simulation for $RH$.

Any suggestions how I could proceed? Simulink is possible, but just a script-based solution would be even better.

• I like "R" because while it is (slightly) klugy, it is free, and it has a stunningly wider variety of toolboxes, called libraries, that are also free. You can make and sell products day 1, without paying thousands of dollars per seat per year for a professional license. Can I give you an "R" friendly answer? Also - my experience with engineering curriculum is that they (sadly) teach you to focus on the mean, and not balance the central tendency with tendency of variation. What does it mean if your parameters are not infinitely precise? :) – EngrStudent Jun 10 '15 at 12:24
• Shouldn't there be a plus sign in front of $[k1\; k2]$ instead of the minus sign? – fibonatic Jun 10 '15 at 15:09

• I think lsim was the kind of function I was looking for, thanks! Why should I choose $B=k_1+k_2$? I mean only $k_2$ should act on the input $RH_{ext}$. My problem is basically what to do with the constant $k_1$ . – donald Jun 11 '15 at 6:35
• Introducing $x$ makes sense, excellent! – donald Jun 11 '15 at 9:27