scilab: graphics -...

39
Scilab: Graphics Manjusha S. Joshi, [email protected] Bhaskaracharya Pratishthana, www.bprim.org September 30, 2010 Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org ) Scilab: Graphics September 30, 2010 1/1

Upload: others

Post on 22-Mar-2020

23 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Scilab: Graphics

Manjusha S. Joshi,[email protected]

Bhaskaracharya Pratishthana,www.bprim.org

September 30, 2010

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 1 / 1

Page 2: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Ploting simple data.

1

2-->x=linspace(12,34,10);3-->y=linspace(-.1,2,10);4-->plot2d(x,y,style=-1)

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 2 / 1

Page 3: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Let us start with simple graphics command

1 -->t=-%pi:0.1:%pi;2

3-->size(t)4 ans =5

6 1. 63.7

8-->plot(t,sin(t))

t is a vector given. We check size of the vector with size| command.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 3 / 1

Page 4: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 4 / 1

Page 5: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try some known graphs:

cos(x)

x2

exp(x)

tan(x)1x

e2πix

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 5 / 1

Page 6: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

y = 3x + x sin x

1

2>deff(’[y]=g(x)’,’y=3*x+x.*sin(x)’)3-->x=1:.5:100;4-->y=g(x);5-->plot(x,y)6

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 6 / 1

Page 7: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

y = 3x + x sin x

1

2-->deff(’[y]=h(x)’,’y=3*x+x.*sin(x)’)3-->x=1:.5:100;4-->fplot2d(x,h)5

Use of fplot2d allows you to directly plot function, with out asking tocompute its value for given data points.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 7 / 1

Page 8: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

1 -->function [y]=f(x)2>y=x*abs(x)/(1+x^2);3>endfunction

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 8 / 1

Page 9: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 10: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 11: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 12: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 13: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 14: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 15: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 16: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Try with Help:

plot2d(x,y)

fplot2d(x,f)

subplot : Multiple graphs

xgrid : displays grid

xtitle : title of the figure

xclear : Clears one or more windows

clf() : Clears the grpahic window

xbasc: Clears graphic window and erase recorded graphics

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 9 / 1

Page 17: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Choice of good interval for the graph is imporatant.

Smoothness of the graph changes with number of points cosdiered inthe given interval. Always check size of the vector you are using forplotting.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 10 / 1

Page 18: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Choice of good interval for the graph is imporatant.Smoothness of the graph changes with number of points cosdiered inthe given interval. Always check size of the vector you are using forplotting.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 10 / 1

Page 19: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Also check for zeros of the function and make sure that you want toinclude it in the interval or exclude it.

Before drawing check what you have asked to draw.

You will be happy to see the figure which you already thought.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 11 / 1

Page 20: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Also check for zeros of the function and make sure that you want toinclude it in the interval or exclude it.

Before drawing check what you have asked to draw.

You will be happy to see the figure which you already thought.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 11 / 1

Page 21: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Also check for zeros of the function and make sure that you want toinclude it in the interval or exclude it.

Before drawing check what you have asked to draw.

You will be happy to see the figure which you already thought.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 11 / 1

Page 22: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 13 / 1

Page 23: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

1 -->deff(’z=f(x,y)’,’z=x^3-y^3’)2

3-->x=-3:0.2:3 ;y=x ;4

5-->clf() ;fplot3d(x,y,f)

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 14 / 1

Page 24: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 15 / 1

Page 25: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

z = sin(x2)− y2

1->deff(’z=f(x,y)’,’z=sin(x^2)-y^2’)2

3

4->x=-3:0.2:3 ;y=x ;5

6->clf() ;fplot3d1(x,y,f)

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 16 / 1

Page 26: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 17 / 1

Page 27: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

We can label X -axis, Y -axis and assign title for the graph:

1 -->xlabel(’X’);2

3 -->ylabel(’ Y-axis’);4

5 -->xtitle(’ Graph of sin(x)’);6 -->plot(sin(x))

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 18 / 1

Page 28: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

We want to compare some graphs. With same set of points. In that case,we can have more than one graph at a time.

1 >> x=-2:.01:22 >> y=x.^33 >> z=x.^54 >> w= sin(x)5 >> plot(x,y,x,z,x,w)

Observe the occurrence of x for each of the function in the plot command.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 19 / 1

Page 29: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Though, there are different colours for each graph, since there are morethan one graph in one graph window. We would like to know which graphsgoes to which function.for that ‘legend’ command can be used.

1 >> legend(’x^3’,’x^5’,’sin(x)’)

Will put colour marks with the function name.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 20 / 1

Page 30: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 21 / 1

Page 31: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

1 -->subplot(2,2,1)2

3 -->plot2d(x,sin(x))4

5-->subplot(2,2,2)6

7-->plot2d2(x,sin(x),[3])8

9-->subplot(2,2,3)10

11-->plot2d3(x,sin(x),[4])12

13-->subplot(2,2,4)14

15-->plot2d4(x,sin(x),[5])

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 22 / 1

Page 32: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

contour draws level curves of the given surface. It compute max and minfor the surface. Then divide open interval (min, max) into number of levelcurves we asked for. Accordingly it draws the contour.

1 deff(’z=f(x,y)’,’z=x.*sin(x)+y.*cos(y)’)2 x=-3: .1: 3; y=x;3 feval(x,y,f)4

5 contour(x,y,f,5)

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 23 / 1

Page 33: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

contour draws level curves of the given surface. It compute max and minfor the surface. Then divide open interval (min, max) into number of levelcurves we asked for. Accordingly it draws the contour.

1 deff(’z=f(x,y)’,’z=x.*sin(x)+y.*cos(y)’)2 x=-3: .1: 3; y=x;3 feval(x,y,f)4

5 contour(x,y,f,5)

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 23 / 1

Page 34: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Another contour

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 24 / 1

Page 35: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

Pie graph

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 25 / 1

Page 36: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

1

2 pie([1, 2, 5])

since 1+2+5=8, we will see a circle divided in to 8 parts, out of which 1,2 and 5 parts are denoted by different colours.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 26 / 1

Page 37: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

From graphics window of scilab, choose option form file menu ’export’.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 27 / 1

Page 38: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

From graphics window of scilab, choose option form file menu ’export’.

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 27 / 1

Page 39: Scilab: Graphics - content.inflibnet.ac.incontent.inflibnet.ac.in/.../11/ET/49-11-ET-V1-S1__scilab-graphics-advpune-1.pdf · Manjusha S. Joshi,manjusha.joshi@gmail.com (Bhaskaracharya

In LATEX use command

1 \includegraphics{filename.jpg}

Make sure the path of the figure file given correctly. Use pdflatex toconvert TEX file to pdf.Make sure that you have include graphics package in the preamble (before\begin{document}) of your TEX file.\usepackage{graphicx}

Manjusha S. Joshi,[email protected] (Bhaskaracharya Pratishthana,www.bprim.org )Scilab: Graphics September 30, 2010 28 / 1