Path: support / 2014-11-10-scilab.sagews
Description:

Examples for support purposes.

Views: 1079155
Image: ubuntu2004-dev
Project: Support and Testing

Playing around a little with SciLab in SageMathCloud. Following [Scilab for very beginners](file:///Users/wstein/Downloads/Scilab_beginners.pdf).

Note: there are currently annoying control codes in the output, when you use "%scilab".

Note: If you make a command-line terminal on SageMathCloud and just type scilab it fails, but if you type scilab -nw it works.

```scilab('4+5')
```
9.
```%scilab

4+5
```
``` ans = 9.```
```%default_mode scilab
```
``` 57/4
```
``` ans = 14.25```
```(2+9)^5
```
``` ans = 161051.```
```2+3.4
```
``` ans = 5.4```
```sqrt(9)
```
``` ans = 3.```

We can't just write %e as in the tutorial, since that is SMC's notation to switch to a different mode for the cell.

```%scilab
%e
```
``` %e = 2.7182818```
```2+3*%i
```
``` ans = 2. + 3.i```
```(1+sqrt(5))/2
```
``` ans = 1.618034```
```exp(10)/factorial(10)
```
``` ans = 0.0060699```
```a
```
``` !--error 4 Undefined variable: a```
```a=%pi/4
```
``` a = 0.7853982```
```a
```
``` a = 0.7853982```
```function d=dollars(e,t);
d=e*t;
endfunction
```
```dollars(200,1.4)
```
``` ans = 280.```
```function y=f(x);
y=36/(8+exp(-x));
endfunction
```
```function y=g(x);
y=4*x/9+4;
endfunction
```
```f(10)
```
``` ans = 4.4999745```
```g(12.5)
```
``` ans = 9.5555556```
```v=[3;-2;5]
```
``` v = 3. - 2. 5.```
```m=[1 2 3;4 5 6;7 8 9]
```
``` m = 1. 2. 3. 4. 5. 6. 7. 8. 9.```
```m*m
```
``` ans = 30. 36. 42. 66. 81. 96. 102. 126. 150.```
```3:10
```
``` ans = 3. 4. 5. 6. 7. 8. 9. 10.```
```1:2:10
```
``` ans = 1. 3. 5. 7. 9.```

I don't think SMC has automatic support for scilab plots. If there were interest, it would probably be easy to implement.

```plot(1,2,".r")
```

But you can display plots anyways as follows:

```%sage
def show_plot():
scilab.eval("xs2svg(gcf(),'/tmp/scilab.svg')"); salvus.file("/tmp/scilab.svg")
```
```%sage show_plot()
```
```plot([1,3],[2,5])
```
```%sage show_plot()
```
```function y=f(x)
y=(x^2+2*x)*exp(-x)
endfunction
x=linspace(-2,5,50);
plot(x,f)
```
```Warning : redefining function: f . Use funcprot(0) to avoid this message ```
```%sage show_plot()
```
```clf
X=[1,2,5];n1=[5,10,5];n2=[6,8,7];
bar(X,[n1',n2'])
```
``` ```
```%sage show_plot()
```
```

```