# How to Model an LPV System in Xcos and Extract Individual States

**URL:** https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552
**Category:** Xcos
**Created:** [June 13, 2024, 9:07am UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552 "2024-06-13T09:07:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)
#### Post date: [June 13, 2024, 9:07am UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552/1 "2024-06-13T09:07:24Z")

</div>

Hello everyone,

I’m currently working on modeling a Linear Parameter-Varying (LPV) system in Xcos and have run into a few questions.

### Current Challenges

1. **Modeling LPV System in Xcos** :

2. **Continuous State-Space System Block** :

Any help or guidance would be greatly appreciated!

Thank you!

---

<div class="post-metadata">

### Author: ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)
#### Post date: [June 13, 2024, 9:38am UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552/2 "2024-06-13T09:38:31Z")

</div>

Hello,

For the first point, I am affraid that for a general state-space system with state x, input u and output y

\begin{align} x'&=f(t,x,u),\\ y&=g(t,x), \end{align}

you will have to use the Scilab function block ([scifunc\_block\_m - Scilab function block](https://help.scilab.org/scifunc_block_m)) and as many integration blocks ([INTEGRAL\_f - Integration](https://help.scilab.org/INTEGRAL_f.html)) as the dimension of x.

For the second point, you can easily extract the state components by adding extra lines to the matrices C and D. For example if you have the following system with a state x of dimension n and an input u of dimension m

\begin{align} x'&=Ax+Bu,\\ y&=Cx+Du, \end{align}

you can define \tilde C=[C;\mathbf{I}] and \tilde D=[D;\mathbf{0}] where \mathbf{I} is the n\times n identity matrix and \mathbf{0} the n\times m zero matrix. Then the LTI system (A,B,\tilde C,\tilde D) will have an output \tilde y whose last n components are those of x.

S.

---

<div class="post-metadata">

### Author: ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)
#### Post date: [June 13, 2024, 10:48am UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552/3 "2024-06-13T10:48:44Z")

</div>

Thank you, so these to examples attached are not the right solution?

 ![Screenshot from 2024-06-13 12-42-47](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/3a098f4cb1b7b1ef5a653d2fb868f4cef649be98.png)  
[StateSpace\_Total.zcos](https://scilab.discourse.group/uploads/short-url/1TdAqbwp5EXa7EiOZdi33P9RVm4.zcos) (5.6 KB)

---

<div class="post-metadata">

### Author: ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)
#### Post date: [June 13, 2024, 10:54am UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552/4 "2024-06-13T10:54:54Z")

</div>

Probably this is a good example:

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/abc6186f6916efd02794e462e73e16a6cc81231a.png)

Source:

> **[Module 5: State Feedback](https://scilabdotninja.wordpress.com/scilab-control-engineering-basics/module-5-state-feedback/)**
>
> Module 5: State Feedback This article is contained in Scilab Control Engineering Basics study module, which is used as course material for International Undergraduate Program in Electrical-Mechanic…

---

<div class="post-metadata">

### Author: ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)
#### Post date: [June 13, 2024, 12:17pm UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552/5 "2024-06-13T12:17:08Z")

</div>

> [@Smart](#):
>
> Thank you, so these to examples attached are not the right solution?

What do yo mean ? It depends what you want to do with x afterwards. It is better to use a LTI system block and output the whole state x (taking C=\mathbf{I} and D=\mathbf{0}), then you can do what you want. But rebuilding the LTI block with elementary block is overkill, unless you need to add perturbations (like in your diagram above).

S.

---

<div class="post-metadata">

### Author: ![Smart](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Smart](https://scilab.discourse.group/u/Smart)
#### Post date: [June 13, 2024, 2:17pm UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552/6 "2024-06-13T14:17:54Z")

</div>

So using the state space Block and the example of ninja is not the smart way?

[https://help.scilab.org/CLSS](https://help.scilab.org/CLSS)

Sorry @mottelet, please help me again. I should use the [scifunc\_block\_m - Scilab function block](https://help.scilab.org/scifunc_block_m) for the matrices, right?  
And in this case I could model a LPV system, too?

---

<div class="post-metadata">

### Author: ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)
#### Post date: [June 13, 2024, 3:57pm UTC](https://scilab.discourse.group/t/how-to-model-an-lpv-system-in-xcos-and-extract-individual-states/552/7 "2024-06-13T15:57:28Z")

</div>

> [@Smart](#):
>
> So using the state space Block and the example of ninja is not the smart way?

There is no smart or not smart way, this is just a matter of taste.

If you have a few number of states, e.g. two, I would not use the scifunc block and directly compose the diagram for individual states. However, if you want to take advantage of the matrix algebra, then use this block. Here is an example for the system (a spring with damping increasing with time):

\begin{align} x'&=f(t,x,u)=A(t)x+Bu,\\ y&=Cx, \end{align}

with A(t)=\left(\begin{array}{cc}0 &1\\-1 & -\frac{t}{10}\end{array}\right):

 ![Screenshot 2024-06-13 at 18.01.22](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/43bc2167c508384541fe3d8e1527e9f42879650f.jpeg)

Here is the code of the function in the block:

 ![Screenshot 2024-06-13 at 18.01.30](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/308f3b69d9b73a91cde090440783dfa05db5c1c3.jpeg)  
[nonstat.zcos](https://scilab.discourse.group/uploads/short-url/fz7DDqiIFDomNH8kO7vvdZlTkhZ.zcos) (4.0 KB)
