问题
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:
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:
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 = function(u1, u2, ...);
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:
open the Scilab Multiple Values Request
by double clocking on the block, Ctrl+B or right click and select Block Parameters ...
:
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:
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.
来源:https://stackoverflow.com/questions/54764607/include-a-scilab-function-script-as-a-block-in-xcos-scicos