0

As the title says I want to include a block where I can run a scilab expression/function/script given certain inputs. I can see xcos/scicos can include C, Fortran and Modelica. There is a Expression block:

enter image description here

but the functions are pretty limited:

sin, cos, tan, exp, log, sinh, cosh, tanh, int, round, ceil, floor, sign, abs, max, min, asin, acos, atan, asinh, acosh, atanh, atan2, log10.

for example if I want to solve a second order equation of ax^2+bx+c=d there are no sqrt or power/^ operators/functions! Ideally I want to just run a Scilab script/function where I can have complete freedom. I would appreciate if you could help me know if there is such a block in either xcos or scicos.

1 Answer 1

2

Thanks to Rupak and Anuradha from Spoken-Tutorial IIT Bombay I found the solution. Create a Scilab function as:

function [y1, y2, ...] = myFunction(u1, u2, ...)
    // some commands ...
    yi = // return value;
endfunction

and save it as myFunction.sci in your preferred location.

Then execute the function once (in editor) or run the command:

exec('path\to\myFunction.sci', -1)

in the console so it will be in the Scilab memory.

Then use the Scilab function block in your block diagram:

enter image description here

open the Scilab Multiple Values Request by double clocking on the block, Ctrl+B or right click and select Block Parameters ...:

enter image description here

Here you can specify the size of input and output matrices. For example [1,1;2,3] refers to two matrices with 1×1 and 2×3 sizes. By selecting OK the Scilab Input Value Request will open:

enter image description here

here you can put the function you just defined y=myFunction(u); or use any other Scilab built in syntax. Now simply select OK four times till the settings are finished.

For a more elaborate example you may follow this YouTube tutorial.

Sign up to request clarification or add additional context in comments.

1 Comment

Anyone know how to use parameters inside the function? I can't find an example anywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.