# How to implement discrete dynamic system in Xcos v2024.1.0?

**URL:** <https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114>\
**Category:** Xcos\
**Created:** [January 27, 2026, 4:10pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114 "2026-01-27T16:10:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Student](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Student](https://scilab.discourse.group/u/Student)\
**Post date:** [January 27, 2026, 4:10pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/1 "2026-01-27T16:10:19Z")

</div>

I have been developing a Xcos simulation where I have a disturbance observer in discrete domain. My intention was to implement the observer itself as a Scilab function invoked in periodic manner from the _scifunc\_block\_m_ block i.e. the block has an event port connected to the clock source. May I ask you for an advice how to properly handle the observer state. In other words I need to have some variables which values are persistent between the individual clock events.

I have noticed that the _scifunc\_block\_m_ has some discrete state in the configuration dialog. Is it intended for such usage? If so, how can I access to the state in the function code? Thanks in advance for your answer.

---

<div class="post-metadata">

**Author:** ![Student](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Student](https://scilab.discourse.group/u/Student)\
**Post date:** [February 10, 2026, 3:04pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/2 "2026-02-10T15:04:53Z")

</div>

I have decided to implement much more simple discrete system at the beginnig. I have attempted to implement the discrete first order low pass filter. So I have just defined the below given function in a separate _.sci_ file

```auto
function [xnew, y1]=Digital_low_pass_filter(flag, x, u1, rpar, ipar)
    
    disp("ARGS: " + string(argn(2))); 
    disp("FLAG: " + string(flag));
    
    select flag
    case 1 then
    // system output update (occurs in every time step of the simulation)
    disp("Flag value: 1");
    y1 = x;
    xnew = x;
   
    case 2 then
    // system dicrete state update (occurs only at discrete event) 
    disp("Flag value: 2");
    T = rpar(1);
    tau = rpar(2);
    a = T/(T + tau);
    b = 1 - a;
    xnew = a*u1 + b*x;
    y1 = [];
   
    case 3 then 
    // continuous state update
    y1 = [];
    xnew = x; 
   
    case 4 then
    // init
    disp("Flag value: 4");
    xnew = 0;
    y1 = [];
        
    case 5 then 
    // end of simulation 
    disp("Flag value: 5");
    y1 = []; 
    xnew = x; 
        
    case 6 then 
    // derivative computation
    disp("Flag value: 6");
    y1 = []; 
    xnew = x; 
        
    case 9 then 
    // zero-crossing
    disp("Flag value: 9");
    y1 = []; 
    xnew = x; 
        
    else
    // default
    disp("Unexpected flag value.");
    y1 = [];
    xnew = x;
    end
endfunction

```

Then I have prepared very simple Xcos model

 ![Simulation_model](https://global.discourse-cdn.com/free1/uploads/utc/original/2X/2/23cc4efcfe3f4769fae0ced2d7b1fea3e37b2f53.png)

The _scifunc\_block\_m_ parameters have been set according to the attachment.

 ![Block_parameters](https://global.discourse-cdn.com/free1/uploads/utc/original/2X/d/d2faadab61acfba8af15cc112863c367175cf92e.png)

Unfortunately the simulation crashes. The diagnostic printing in the Console window occurs: “ARGS: 5“ and a warning occurs at the _scifunc\_block\_m_ right down corner. Namely there is “_Wrong number of input arguments.Expected 3._“ written.

May I ask you for an advice how to implement this simple discrete system via the scifunc\_block\_m?

---

<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:** [February 12, 2026, 9:33am UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/3 "2026-02-12T09:33:22Z")

</div>

Hello,

I think you are mixing up scifunc\_block\_m and generic\_block3 (I recognize that generic\_block3 is not sufficiently documented and misses examples). Maybe @davidcl can confirm ?

S.

---

<div class="post-metadata">

**Author:** ![Student](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Student](https://scilab.discourse.group/u/Student)\
**Post date:** [February 12, 2026, 1:25pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/4 "2026-02-12T13:25:41Z")

</div>

Hello, thank you for your reaction. I have placed the _scifunc\_block\_m_ block from the User defined functions category into my simulation. Why do you think I have used the _generic\_block3?_

---

<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:** [February 12, 2026, 2:08pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/5 "2026-02-12T14:08:36Z")

</div>

You have used a `scifunc_block_m` but your function prototype

```scilab
[xnew,y1] = Digital_low_pass_filter(flag, x, u1, rpar, ipar)

```

has the argument list of functions used by the `generic_block3` block. Inside a `scifunc_block_m`, if you call your function, there is no mecanism that would give you values to `flag, x, u1, rpar, ipar` (unless you pass actual arguments by defining them explicitely).

S.

---

<div class="post-metadata">

**Author:** ![Student](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Student](https://scilab.discourse.group/u/Student)\
**Post date:** [February 12, 2026, 3:58pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/6 "2026-02-12T15:58:26Z")

</div>

I see. May I ask you for an advice how to modify the function prototype to be in accordance with the _scifunc\_block\_m_?

---

<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:** [February 12, 2026, 4:24pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/7 "2026-02-12T16:24:27Z")

</div>

can you attach your diagram to your post (the one with the screenshots) ?

---

<div class="post-metadata">

**Author:** ![Student](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Student](https://scilab.discourse.group/u/Student)\
**Post date:** [February 12, 2026, 8:50pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/8 "2026-02-12T20:50:58Z")

</div>

[Digital\_low\_pass\_filter.sci](https://scilab.discourse.group/uploads/short-url/eDRppvwgvsr7eYJfNKDxEn4zFXW.sci) (1.2 KB)

[Digital\_low\_pass.zcos](https://scilab.discourse.group/uploads/short-url/nu1ZRGqUCUKPzt4fDP7sIGt8r2Z.zcos) (4.2 KB)

I have just attached the Xcos model along with the function definition.

---

<div class="post-metadata">

**Author:** ![Student](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Student](https://scilab.discourse.group/u/Student)\
**Post date:** [February 17, 2026, 5:54am UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/9 "2026-02-17T05:54:49Z")

</div>

Do you see anything wrong in the Xcos model or the function definition?

---

<div class="post-metadata">

**Author:** ![davidcl](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/davidcl/32/1029_2.png) [@davidcl](https://scilab.discourse.group/u/davidcl)\
**Post date:** [March 31, 2026, 9:22am UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/10 "2026-03-31T09:22:09Z")

</div>

Hello,

After investiguation, it looks that `flag` is resolved to a Scilab macro. Calling `string(flag)` expect 3 output argument ; this is an issue.

To have a better error report, I enable proper call stack when debug is enabled. You will get the expected error and stacktrace (with lines). See [Xcos: report Scilab intermediate errors in debug (!1680) · Merge requests · scilab / scilab · GitLab](https://gitlab.com/scilab/scilab/-/merge_requests/1680)

---

<div class="post-metadata">

**Author:** ![davidcl](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/davidcl/32/1029_2.png) [@davidcl](https://scilab.discourse.group/u/davidcl)\
**Post date:** [March 31, 2026, 12:26pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/11 "2026-03-31T12:26:31Z")

</div>

In the dialog box of `scifunc_block_m`, the `flag` variable is not used by Xcos.

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

The `flag` variable you used here is the `flag()` function from colormaps. Thus the error.

---

<div class="post-metadata">

**Author:** ![Student](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Student](https://scilab.discourse.group/u/Student)\
**Post date:** [April 1, 2026, 8:25pm UTC](https://scilab.discourse.group/t/how-to-implement-discrete-dynamic-system-in-xcos-v2024-1-0/1114/12 "2026-04-01T20:25:20Z")

</div>

Thank you very much for your reaction. Does it mean that I have to remove the flag parameter from the function header? If so what is the correct approach for control of the _scifunc\_block\_m_ i.e. what is the mechanism how the solver interacts with the _scifunc\_block\_m_?
