Matrix S/H algebraic loop issue

This might be a bug or usability issue, but I’m not sure which at the moment.

I’m trying to run a simple feedback model with the S/H block as shown:

But it’s giving an error saying ‘algebraic loop’.

However, when I run the same code extracted from the S/H source code in a C block, I don’t get the error. The successful digram is as follows:

with the C block configration:

and the code is:

#include "scicos_block4.h"

void toto(scicos_block *block,int flag)
{
    /* c     Copyright INRIA

    Scicos block simulator
    returns sample and hold  of the input */

    if (flag == 1)
    {
        int m = GetInPortRows(block, 1);
        int n = GetInPortCols(block, 1);
        void *u = GetInPortPtrs(block, 1);
        void *y = GetOutPortPtrs(block, 1);
        int sz = GetSizeOfOut(block, 1);
        memcpy(y, u, m * n * sz);
    }
}

It would be nice to have this S/H generic block working without the algebraic loop error. Is this a bug or am I missing something? The block works fine without the feedback.

Thank you

Apologies for not saying; this was tested on Windows 11 using version 2026.0.0.

Hello,

The presence of the S/H block does not change the deal here, as at each event time you have an algebraic loop: the output y of the sum block is equal to y + your matrix. You can fix this by inserting a discrete delay between the S/H and the feedback return. But maybe you are trying to do something else…

S.

Thank you S for your response.

What I’m trying to do is run this setup (adding the inputs together after an event-triggered delay) not only for scalars, but also for a matrix. The ‘1/z’ blocks (DOLLAR_f, DOLLAR, and DOLLAR_m) all work fine in this configuration for scalar inputs, but not for matrices. If I replace the ‘S/H’ block in the above diagram with a ‘1/z’ block and use just a scalar as input, I don’t get an algebraic loop. And I’m assuming the ‘1/z’ and ‘S/H’ blocks should have similar delay characteristics; hence why I wouldn’t expect a feedback error.

Another important note is that the above code was copied from the C source code for the ‘S/H’ block (see ‘samphold4_m.c’ file in the ‘scicos_blocks’ project in the Scilab source (referenced in help)). All I’ve done is copy this into a C block, and I don’t get the algebraic loop error. But I do when I use the block itself. There seems to be an inconsistency somewhere that I’m a bit confused about.

I could look into the source code to investigate what’s going on, but I thought I would try here first.

Is it all about a possible implementation of the feature you are asking for in another recent topic (https://scilab.discourse.group/t/dynamically-select-matrix-elements) ?

S.

There is no delay in a S/H block.

S.

Right, thank you. That’s where I’m getting confused. So I’ll continue using my C block for now.

And yes, it’s somewhat related to my other post, but not directly. My other post is about dynamic matrix element selection, and would like to use standard blocks as much as possible. Here, I just need an event-driven delay block for matrices. So I may have to resort to building my own blocks.

If you need a block with two inputs i,j and giving ouput a(i,j) where a is defined in the context then no, Scilab does not have such a built-in block. The block which could implement it is the Expression block (EXPRESSION - Mathematical expression), but it uses a Scilab expression.

Thank you Stephane, I will try that.

Since I have your attention, can you help me figure out how the ‘scifunc_block_m’ block can generate events? Or should I start a separate topic?

please start a new topic