OpenLLM-France/wikimedia huggingface dataset:
# How to Use Rhino Mocks/Introduction
## Basic Usage

1. Create a mock repository:
2. Add a mock object to the repository:
If you're using C# 2.0, you may use the generic version and avoid upcasting:
3. "Record" the methods that you expect to be called on the mock object:
Note that the parameter values provided in these calls represent those values we expect our mock to be called with. Similarly, the return value represents the value that the mock will return when this method is called.
You may expect a method to be called multiple times:
4. Set the mock object to a "Replay" state where, as called, it will replay the operations just recorded.
5. Invoke code that uses the mock object.
6. Check that all calls were made to the mock object.
# How to Type
## Table of Contents

* Introduction to typing (july 3 2011)
* The Middle Row (july 3 2011)
* The Ends of the Top (july 3 2011)
# How to Type/The Ends of the Top
## e and i

Step 1: Put your fingers on the middle row, and move the middle finger up to e to type e.
Step 2: Practice doing this:
# How to Use Rhino Mocks

Rhino Mocks is a mock object framework for the .NET platform. It is freely available from Ayende Rahien.

## Table of Contents

Introduction
Out and Ref Parameters
Testing Events
Debugging Exceptions
Mocks, Dynamic Mocks, Partial Mocks
# How to Use Rhino Mocks/Debugging Exceptions
## ExpectationViolationException

The first time I got an ExpectationViolationException , I was baffled. Here's what it looked like:
* failed: Rhino.Mocks.Exceptions.ExpectationViolationException :
* IInternalSearchService.ProcessIndexingRequest(collaboration.thecompany.com.internalServiceContractsObjects._2007._12.AuthenticationCredentials,
* "Zardoz", \[collaboration.thecompany.com.internalSearch._2007._12.IndexingWork\]); Expected #0, Actual #1.
* IInternalSearchService.ProcessIndexingRequest(collaboration.thecompany.com.internalServiceContractsObjects._2007._12.AuthenticationCredentials,
* "Zardoz", \[collaboration.thecompany.com.internalSearch._2007._12.IndexingWork\]); Expected #1, Actual #0.
Cryptic, and ultimately not very helpful (at least to me). Basically, all you know when seeing this is that something went wrong with an expectation you set up in your test. Here are a few more things to know, and things you can do to try and debug these kinds of problems:
* Expectations have to do with both the expected calls _and_ the expected parameters. If, in your test, you say something like, Expect.Call(myMock.DoSomething(fooObject)), Rhino.Mocks expects that myMock.DoSomething will be called with _the exact instance_ of fooObject.
* When Rhino.Mocks compares expected parameters (like fooObject in the previous point), it uses the object's Equals method. This means that even if your expected object has all the same property values, etc., comparison will fail unless you are able to pass the _exact_ expected instance (or unless you override Equals, which is generally a not-so-great idea). In 3.4, Rhino.Mocks introduced the Property.AllPropertiesMatch constraint which does a reflective property comparison for objects, e.g.,
* Expect.Call(myMock.DoSomething(fooObject)).IgnoreArguments.Constraints(Property.AllPropertiesMatch(fooObject));
    I.e., expect a call to myMock.DoSomething, "ignoring" all passed arguments, but constrained by the following: that the first arguments properties match fooObject's properites exactly.
* You can add a Rhino.Mocks logger to print data to the console. This can give a bit more detail on what's happening where and why. Just add the following line to your test, before the mocking work:
* RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
* When Rhino.Mocks compares two objects during expectation validation, and something goes wrong, the data you get in the exception message comes from the ToString on the objects. So, you can override ToString in the class of the objects which are being compared; override it to give you some info about what might be going wrong with the comparison (like, override it to spit out the various properties on the objects).
# How to Type/The Middle Row

Keyboards are arranged in various ways depending on location, intended language, and history. This following covers the most common English language arrangement, known as QWERTY,. Its pattern is not the only in use, even for English language users. The Dvorak keyboard, for instance, is widely available as an alternative, especially since the development of electronic keyboards used with computers. Alternative layouts are often intended for efficiency, putting the most common keys under the strongest fingers, or placing common letter combinations on opposite sides of the keyboard to encourage alternation between left and right hands; opinions differ as to how successful it has been.
The Middle Row, or Home row of the QWERTY keyboard is that row which has a, s, d, f, g, h, j, k, l, and ;.

## f and j

Step 1: Place your two index fingers on the f and j. You will know where they are by the bumps on the key.
Step 2: Practice f and j by doing this:

## The Spacebar

The Spacebar is used to put spaces through words.
Step 1: Put your two thumbs on the space bar and use them when you need to.
Step 2: Practice like this:

## d, s, a, k, l, and ;

Step 1: Put your middle fingers on d and k and practice like this:
Step 2: Put your ring fingers on s and l and practice like:
Step 3: Put your pinkies on a and ; and practice like:

## g and h

Step 1: Use your index fingers to shift from f to g, and j to h. Like so:

## Your first words

Step 1: Practice these words:
# LMIs in Control/pages/CT-SOFS

LMIs in Control/pages/CT-SOFS
In view of applications, static feedback of the full state is not feasible in general: only a few of the state variables (or a linear combination of them, $y=Cx(t)$, called the output) can be actually measured and re-injected into the system.
So, we are led to the notion of static output feedback

## The System

Consider the continuous-time LTI system, with generalized state-space realization $(A,B,C,0)$
    ${\begin{aligned}{\dot {x}}(t)&=Ax(t)+Bu(t)\\y(t)&=Cx(t)\\\end{aligned}}$

## The Data

* $A\in \mathbb {R} ^{n\times n},B\in \mathbb {R} ^{n\times m},C\in \mathbb {R} ^{p\times n}$
* $x\in \mathbb {R} ^{n},y\in \mathbb {R} ^{p},u\in \mathbb {R} ^{m}$

## The Optimization Problem

This system is static output feedback stabilizable (SOFS) if there exists a matrix F such that the closed-loop system
${\dot {x}}=(A-BKC)x$
(obtained by replacing $u=-Ky$ which means applying static output feedback) is asymptotically stable at the origin

## The LMI: LMI for Continuous Time - Static Output Feedback Stabilizability

The system is static output feedback stabilizable if and only if it satisfies any of the following conditions:
* There exists a $K\in \mathbb {R} ^{m\times p}$ and $P\in \mathbb {S} ^{n}$, where $P>0$, such that
    ${\begin{bmatrix}A^{T}P+PA-PBB^{T}P&PB+C^{T}K^{T}\\KC+B^{T}P&-1\end{bmatrix}}$${\begin{aligned}<0\end{aligned}}$
* There exists a $K\in \mathbb {R} ^{m\times p}$ and $Q\in \mathbb {S} ^{n}$, where $Q>0$, such that
    ${\begin{bmatrix}QA^{T}+AQ-QC^{T}CQ&BK+QC^{T}\\CQ^{T}+K^{T}B^{T}&-1\end{bmatrix}}$${\begin{aligned}<0\end{aligned}}$
* There exists a $K\in \mathbb {R} ^{m\times p}$ and $Q\in \mathbb {S} ^{n}$, where $Q>0$, such that
    ${\begin{bmatrix}QA^{T}+AQ-BB^{T}&B+QC^{T}K^{T}\\B^{T}+KCQ^{T}&-1\end{bmatrix}}$${\begin{aligned}<0\end{aligned}}$
* There exists a $K\in \mathbb {R} ^{m\times p}$ and $P\in \mathbb {S} ^{n}$, where $P>0$, such that
    ${\begin{bmatrix}A^{T}P+PA-C^{T}C&PBK+C^{T}\\K^{T}B^{T}P&-1\end{bmatrix}}$${\begin{aligned}<0\end{aligned}}$

## Conclusion

On implementation and optimization of the above LMI using YALMIP and MOSEK (or) SeDuMi we get 2 output matrices one of which is the Symmeteric matrix $P$ (or $Q$) and $K$

## Implementation

A link to the Matlab code for a simple implementation of this problem in the Github repository:
https://github.com/yashgvd/LMI_wikibooks

## Related LMIs

Discrete time Static Output Feedback Stabilizability
Static Feedback Stabilizability

## External Links

* - LMI in Control Systems Analysis, Design and Applications
* LMI Methods in Optimal and Robust Control - A course on LMIs in Control by Matthew Peet.
* LMI Properties and Applications in Systems, Stability, and Control Theory - A List of LMIs by Ryan Caverly and James Forbes.
* D. d. S. Madeira and J. Adamy, "Static output feedback: An LMI condition for stabilizability based on passivity indices," 2016 IEEE Conference on Control Applications (CCA), Buenos Aires, 2016, pp. 960-965.
# LMIs in Control/pages/D stabilization

$\mathbb {D} _{(q,r)}$-Stabilization
There are a wide variety of control design problems that are addressed in a wide variety of different ways. One of the most important control design problem is that of state feedback stabilization. One such state feedback problem, which will be the main focus of this article, is that of $\mathbb {D} _{(q,r)}$-Stabilization, a form of $\mathbb {D}$-Stabilization where the closed-loop poles are located on the left-half of the complex plane.

## The System

For this particular problem, suppose that we were given a linear system in the form of:
    ${\begin{aligned}\rho x&=Ax+Bu,\\\end{aligned}}$
where $x\in \mathbb {R} ^{n}$, $u\in \mathbb {R} ^{r}$, and $\rho$ represents either the differential operator (in the continuous-time case) or the one-step forward operator (for the discrete-time system case). Then the LMI for determining the $\mathbb {D} _{(q,r)}$-stabilization case would be obtained as described below.

## The Data

In order to obtain the LMI, we need the following 2 matrices: $A{\text{ and }}B$.

## The Optimization Problem

Suppose - for the linear system given above - we were asked to design a state-feedback control law where $u=Kx$ such that the closed-loop system:
    ${\begin{aligned}\rho x&=(A+BK)x\\\end{aligned}}$
is $\mathbb {D} _{(q,r)}$-stable, then the system would be stabilized as follows.

## The LMI: $\mathbb {D} _{(q,r)}$-Stabilization

From the given pieces of information, it is clear that the optimization problem only has a solution if there exists a matrix $W$ and a symmetric matrix $P$ that satisfies the following:
       ${\begin{aligned}{\begin{bmatrix}-rP&&qP+AP+BW\\qP+PA^{T}+{W^{T}}{B^{T}}&&-rP\end{bmatrix}}<0\end{aligned}}$

## Conclusion:

Given the resulting controller matrix $K=WP^{-1}$, it can be observed that the matrix is $\mathbb {D} _{(q,r)}$-stable.

## Implementation

* Example Code - A GitHub link that contains code (titled "DStability.m") that demonstrates how this LMI can be implemented using MATLAB-YALMIP.

## Related LMIs

      * H stabilization - Equivalent LMI for $\mathbb {H} _{(\alpha ,\beta )}$-stabilization.
      * Continuous Time D-Stability Controller - LMI for deriving a Controller using D-Stability.
      * Continuous Time D-Stability Observer - LMI for deriving an Observer using D-Stability.

## External Links

A list of references documenting and validating the LMI.
* LMI Methods in Optimal and Robust Control - A course on LMIs in Control by Matthew Peet.
* LMI Properties and Applications in Systems, Stability, and Control Theory - A List of LMIs by Ryan Caverly and James Forbes.
* LMIs in Systems and Control Theory - A downloadable book on LMIs by Stephen Boyd.
* LMIs in Control Systems: Analysis, Design and Applications - A book co-authored by Guang-Ren Duan and Hai-Hua Yu.
# LMIs in Control/pages/D-Stabilization of Switched Systems

D-Stability Controller for Switched Systems
This LMI lets you specify desired performance metrics like rising time, settling time and percent overshoot. Note that arbitrarily switching between stable systems can lead to instability whilst switching can be done between individually unstable systems to achieve stability.

## The System

Suppose we were given the switched system such that
    ${\begin{aligned}{\dot {x}}(t)&=A_{i}x(t)+B_{i}u(t)\\y(t)&=C_{i}x(t)+D_{i}u(t)\end{aligned}}$
where $A_{i}\in \mathbb {R} ^{mxm}$, $B_{i}\in \mathbb {R} ^{mxn}$, $C_{i}\in \mathbb {R} ^{pxm}$, and $D_{i}\in \mathbb {R} ^{qxn}$ for any $t\in \mathbb {R}$.
$i\in 1,...,k$ modes of operation

## The Data

In order to properly define the acceptable region of the poles in the complex plane, we need the following pieces of data:
      * matrices $A_{i}$, $B_{i}$
      * rise time ($t_{r}$)
      * settling time ($t_{s}$)
      * percent overshoot ($M_{p}$)
Having these pieces of information will now help us in formulating the optimization problem.

## The Optimization Problem

Using the data given above, we can now define our optimization problem. We first have to define the acceptable region in the complex plane that the poles can lie on using the following inequality constraints:
Rise Time: $\omega _{n}{\leq }{1.8 \over t_{r}}$
Settling Time: $\sigma {\leq }{-4.6 \over t_{s}}$
Percent Overshoot: $\sigma {\leq }{-ln({M_{p}}) \over {\pi }}|{\omega _{d}}|$
Assume that $z$ is the complex pole location, then:
       ${\begin{aligned}{\omega _{n}}^{2}=\|z\|^{2}&=z^{*}z\\{\omega _{d}}=Im{z}&={(z-z^{*}) \over 2}\\{\sigma }=Re{z}&={(z+z^{*}) \over 2}\end{aligned}}$
This then allows us to modify our inequality constraints as:
Rise Time: $z^{*}z-{1.8^{2} \over {t_{r}}^{2}}{\leq }0$
Settling Time: ${(z+z^{*}) \over 2}+{4.6 \over t_{s}}{\leq }0$
Percent Overshoot: $z-z^{*}+{{\pi } \over ln({M_{p}})}|z+z^{*}|{\leq }0$
which not only allows us to map the relationship between complex pole locations and inequality constraints but it also now allows us to easily formulate our LMIs for this problem.

## The LMI: An LMI for Quadratic D-Stabilization

Suppose there exists $P>0$ and $Z$ such that
       ${\begin{aligned}{\begin{bmatrix}-rP&&A_{i}P+B_{i}Z\\(A_{i}P+B_{i}Z)^{T}&&-rP\end{bmatrix}}<0\\A_{i}P+B_{i}Z+(A_{i}P+B_{i}Z)^{T}+2\alpha P&<0,and\\\end{aligned}}$
       ${\begin{aligned}{\begin{bmatrix}A_{i}P+B_{i}Z+(A_{i}P+B_{i}Z)^{T}&&c(A_{i}P+B_{i}Z-(A_{i}P+B_{i}Z)^{T})\\c((A_{i}P+B_{i}Z)^{T}-(A_{i}P+B_{i}Z))&&A_{i}P+B_{i}Z+(A_{i}P+B_{i}Z)^{T}\end{bmatrix}}<0\end{aligned}}$
for $i=1,...,k$

## Conclusion:

The resulting controller can be recovered by
$K=ZP^{-1}$.

## Implementation

The implementation of this LMI requires Yalmip and Sedumi /MOSEK

## External Links

A list of references documenting and validating the LMI.
* LMI Methods in Optimal and Robust Control - A course on LMIs in Control by Matthew Peet.
* LMI Properties and Applications in Systems, Stability, and Control Theory - A List of LMIs by Ryan Caverly and James Forbes.
* LMIs in Systems and Control Theory - A downloadable book on LMIs by Stephen Boyd.
# LMIs in Control/pages/DCGain

The continuous-time DC gain is the transfer function value at the frequency s = 0.

## The System

Consider a square continuous time Linear Time invariant system, with the state space realization $(A,B,C,D)$ and $\gamma \in \mathbb {R} _{>0}$
    ${\begin{aligned}{\dot {x}}(t)=Ax(t)+Bu(t)\\y=Cx(t)+Du(t)\end{aligned}}$

## The Data

$A\in \mathbb {R} ^{n\times n},B\in \mathbb {R} ^{n\times m},C\in \mathbb {R} ^{p\times n},D\in \mathbb {R} ^{p\times m}$

## The LMI: LMI for DC Gain of a Transfer Matrix

The transfer matrix is given by$G(s)=C(sI-A)^{-1}B+D$
The DC Gain of the system is strictly less than $\gamma$ if the following LMIs are satisfied.
    ${\begin{bmatrix}\gamma I&-CA^{-1}B+D\\(-CA^{-1}B+D)'&\gamma I\end{bmatrix}}$${\begin{aligned}>0\end{aligned}}$
OR
    ${\begin{bmatrix}\gamma I&-B^{T}A^{-T}C^{T}+DT\\(-B^{T}A^{-T}C^{T}+DT)'&\gamma I\end{bmatrix}}$${\begin{aligned}>0\end{aligned}}$

## Conclusion

The DC Gain of the continuous-time LTI system, whose state space realization is give by ($A,B,C,D$), is
$K=D-CA^{-1}B$
* Upon implementation we can see that the value of $\gamma$ obtained from the LMI approach and the value of $K$ obtained from the above formula are the same

## Implementation

A link to the Matlab code for a simple implementation of this problem in the Github repository:
https://github.com/yashgvd/LMI_wikibooks

## External Links

* - LMI in Control Systems Analysis, Design and Applications
* LMI Methods in Optimal and Robust Control - A course on LMIs in Control by Matthew Peet.
* LMI Properties and Applications in Systems, Stability, and Control Theory - A List of LMIs by Ryan Caverly and James Forbes.
* -Mathworks reference to DC Gain
# LMIs in Control/pages/DARE

LMIs in Control/pages/DARE

## The System

Consider a Discrete-Time LTI system
    ${\begin{aligned}x_{k+1}=A_{d}x_{k}+B_{d}u_{k}\end{aligned}}$
    ${\begin{aligned}y_{k}=C_{d}x_{k}\end{aligned}}$
Consider A$_d$ ∈ ${\begin{aligned}\mathbb {R} \end{aligned}}$$^{nxn}$ ; B$_d$ ∈ ${\begin{aligned}\mathbb {R} \end{aligned}}$$^{nxm}$

## The Data

The Matrices A$_d$ , B$_d$ , C$_d$ , Q, R are given
Q and R should necessarily be Hermitian Matrices.
A square matrix is Hermitian if it is equal to its complex conjugate transpose.

## The Optimization Problem

Our aim is to find
P - Unique solution to the discrete-time algebraic Riccati equation, returned as a matrix.
K - State-feedback gain, returned as a matrix.
The algorithm used to evaluate the State-feedback gain is given by
    ${\begin{aligned}K=(R+B_{d}^{T}PB_{d})^{-1}B_{d}^{T}PA_{d}\end{aligned}}$
L - Closed-loop eigenvalues, returned as a matrix.

## The LMI: Discrete-Time Algebraic Riccati Inequality (DARE)

An algebraic Riccati equation is a type of nonlinear equation that arises in the context of infinite-horizon optimal control problems in continuous time or discrete time
The Discrete-Time Algebraic Riccati Inequality is given by
    ${\begin{aligned}A_{d}^{T}PA_{d}-A_{d}^{T}PB_{d}(R+B_{d}^{T}PB_{d})^{-1}B_{d}^{T}PA_{d}+Q-P\geq 0\end{aligned}}$
P , Q ∈ ${\begin{aligned}\mathbb {S} \end{aligned}}$$^n$ and R ∈ ${\begin{aligned}\mathbb {S} \end{aligned}}$$^m$ where P > 0, Q ≥ 0, R > 0
P is the unknown n by n symmetric matrix and A, B, Q, R are known real coefficient matrices.
The above equation can be rewritten using the Schur Complement Lemma as :
    ${\begin{bmatrix}A_{d}^{T}PA_{d}-P+Q&A_{d}^{T}PB_{d}\\B_{d}^{T}PA_{d}&R+B_{d}^{T}PB_{d}\end{bmatrix}}$${\begin{aligned}\geq 0\end{aligned}}$

## Conclusion:

Algebraic Riccati Inequalities play a key role in LQR/LQG control, H2- and H∞ control and Kalman filtering. We try to find the unique stabilizing solution, if it exists. A solution is stabilizing, if controller of the system makes the closed loop system stable.
Equivalently, this Discrete-Time algebraic Riccati Inequality is satisfied under the following necessary and sufficient condition:
    ${\begin{bmatrix}Q&0&A_{d}^{T}P&P\\0&R&B_{d}^{T}P&0\\PA_{d}&PB_{d}&P&0\\P&0&0&P\end{bmatrix}}$${\begin{aligned}\geq 0\end{aligned}}$

## Implementation

( X in the output corresponds to P in the LMI )
A link to the Matlab code for a simple implementation of this problem in the Github repository:
https://github.com/yashgvd/LMI_wikibooks

## Related LMIs

LMI for Continuous-Time Algebraic Riccati Inequality
LMI for Schur Stabilization

## External Links

A list of references documenting and validating the LMI.
* - LMI in Control Systems Analysis, Design and Applications
# Introduction to Python Programming/Python Programming - Handling Files
## 7. Files

Python provides for more input and output functions. The simplest method of producing output is using the “print” statement.
There are two methods in which the Python interpreter reads the input provided at the terminal namely:
* raw_input
This command reads whatever is at the terminal as the input regardless of whether it is an expression or not and returns a string.
* Input
The input command evaluates the expressions as regular Python expressions and takes it as input.
The following examples highlight the differences between raw_input and input.

### 7.1. Opening and Closing Files

Till now, we were writing at the input terminal and obtaining output at the terminal. Let’s move further to reading and writing files. Python provides for a plethora of functions to read and write files that may be text, or data files. File manipulation commands such done using a file object.
A list of couple of functions for operations on files are highlighted as examples within explanation provided with the comments. A file can be opened for reading, writing, appending existing text.
The “open” function opens a file that can used to read, write, or append data. For performing any of the above mentioned functions, every file must be opened first.
Please remember to close the file and then check if the actual file has the contents written into the file. Now, let’s go ahead and read the contents of the file that was just written.
There is a Python module “os” that provides methods to perform file-processing operations such as renaming and deleting files. To get the current working directory, do the following.
# Introduction to Python Programming/Python Programming - Acknowledgement

Acknowledgements
I would like to thank my professor Parameshwar P. Iyer who encouraged me to work entirely on my own, the Python Software Foundation that has worked extensively to promote the Python programming community, and the various chapters under its purview, Pyladies Bangalore for giving me the platform to hone my Python programming skills. There were a lot of online resources that I referred to while preparing this book. I want to thank each one of them for their material, and for the time that they devoted for developing the material.
The cover for this book was obtained from the Python official website. So I wish to thank the original creators/designers of the Python language.
Thanks everyone who has contributed either directly or indirectly in the writing of this book.
# Introduction to Python Programming/Python Programming - Class and Objects
## 6. Classes and Objects

Python uses object orientation since its inception owing to which fact creating classes, using classes and objects is absolutely easy.

### 6.1. Creating classes

The class statement creates a new class definition. The user provided name for the class follows the keyword class followed by a colon as follows:
The end user can check if the defined class has a particular method or object or instance defined within the class using the hasattr object.
The end user can add, modify, set, or delete the attributes of classes and objects at any time using the following methods.

### 6.2. Class Built-In Attributes

By default, all Python classes have the following built-in attributes that can be accessed using the dot operator just like the __doc__ attribute that provides the documentation of the class.
* __dict__ : The dictionary of the namespace of the class
* __doc__ : Class documentation string or none, if undefined
* __name__ : Class name
* __module__ : Module name in which the class is defined. This attribute is "__main__" in interactive mode
* __bases__ : A possibly empty tuple containing the base classes, in the order of their occurrence in the base class list.
Trying the above methods for the above defined myclass, we have the following result.
# Introduction to Python Programming/Python Programming - Command Line Arguments
## 8. Command Line Arguments

There is a module sys that needs to be imported to read the command line arguments from the Python interpreter.
Here’s an example.