Tuesday, August 20, 2013

A Hands-on Guide to ScicosLab - Part 2

Define a Zero Vector

--> v = zeros(1:20)

Use Scipad Editor

To launch the embedded editor, type

--> scipad

One can write a sequence of Scicos instructions and save it as *.sci files. To load such a program into ScicosLab, type

--> exec('foo.sci');

Directory operation

It inherits a Linux style,

--> pwd
--> ls
--> cd

To clear terminal screen, use either one

--> ctrl+l
--> clc

Define a Function

For instance,

function [re,im] = compute(v, f)
    re=re+cos(2*%pi*f*v/1000000);
    im=im+sin(2*%pi*f*v/1000000);
    return [re,im];
  endfunction

The return value is a vector [re,im], as you might notice, the Scicos language is C-like but not strong-typed. This function compute takes two params. Notice that the incremental sum is not supported, that is re+=... commits an error. Once loaded into ScicosLab, it works as library functions. You can call it anytime, but after a clear command, it vanishes as all the other customized variables do.

For and While

for i=1:20, printf("%d\n",i); end

Notice that no increment of i is needed. It does so automatically at every loop.

i=1;
while i<=20, printf("%d\n",i);i++; end

TBD.

No comments:

Post a Comment