Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Ejemplo:
Graficar el polinomio de p�gina 624 de CHAPRA COMENTARIOS
A = [ 1 2 1 ; 2 1 4 ; 1 2 2 ]
A^2 //Operaci�n MAtricial
A*A //Operaci�n MAtricial
A.^2 //Operaci�n por elemento
A.*A
Sistemas de ecuaci�n lineal.
s="Hello World"
disp(s)
Podemos correr directamente el script desde el editor o desde la consola con exec(
)
Ejemplos:
for i=1:5
disp(i)
end
for i=1:2:5
disp(i)
end
for i=5:-1:1
disp(i)
end
x=input("x?")
V = [i, x];
disp(V)
xnew=x-(exp(-x)-x)/(-exp(-x)-1);
x=xnew;
end
//Serie de fibonacci
[x y] = newfun(5,2)
http://audition.ens.fr/brette/Scilab/efficientscilab.html
Scilab has two pairs of functions read/write and load/save for handling data and
files.
save and load
This pair of functions is used to save and reload data produced by Scilab. These
are associated with binary files which cannot be read (sensibly) by other programs.
Here is an example:
-->x = rand(4, 4)
x =
-->y = rand(4, 4)
y =
-->clear y
-->x
!--error 4
undefined variable : x
-->y
!--error 4
undefined variable : y
We can now reload these variables from the file we have created:
-->load('prac3.sci')
-->x
x =
-->y
y =
These operate on text files containing numerical data. Their most important use is
to produce data for other programs and to manipulate and plot data from other
sources.
-->z = rand(8,4)
z =
-->write('prac3.out', z)
If you examine the file prac3.out it will look something like:
0.0230194512 0.646285265 0.760393302 0.602659694
0.48545251 0.815384094 0.348678976 0.611731049
0.555323126 0.827969833 0.641170944 0.49271012
0.243523459 0.680952108 0.408767792 0.217371969
0.146170148 0.909257194 0.237243087 0.441845817
0.389484918 0.0130122323 0.566738097 0.979827398
0.481041052 0.0500522447 0.703874052 0.525922459
0.0406747693 0.977949818 0.56603785 0.690982413
Note that only one matrix can be written to a file at any one time. We can read the
data back in to a matrix:
-->z1 = read('prac3.out', 8, 4)
z1 =
-->z3 =read('prac3.out', 2, 5)
z3 =
Saving Graphs
Graphs can be saved in Scilab specific binary files and then reloaded much the same
way that save and load work. The easiest way to save or load a graph is via the
file menu on the graphics window. Again, this is typically used to save graphs when
you leave Scilab to be reloaded when you start Scilab again. Only one graph can be
saved at a time.
Exporting Graphs
Scilab can export graphics in a number of formats. We will only be concerned with
the .eps (encapsulated postscript) format. We will redo the graph from Practical 2.
-->x = linspace(-10, 10, 1000);
-->plot2d(x,y)
To export the graph, go to the file menu on graphics window and select export.
Select Postscript, Landscape and choose a filename. You should then be able to view
the graph outside Scilab using a postscript viewer (e.g. gv on Linux).
Doing Assignment 2
For Linux users this should now be pretty straightforward since we have already
covered everything you need to know. For Windows users the only thing that could
cause problems is keeping track of where the various files are. This can be a bit
tricky since Scilab and WinEdt/MiKTeX tend to look in different places for files.
Again, all of this can vary from user to user so there is no definitive way to
handle this problem. Basically it is up to you to know where yuor files live.
Scilab has to know the file dj.dat is.
WinEdt/MiKTeX has to know where the .eps produced by Scilab is.
Once you have worked this out the mechanics should be more or less straightforward.
About this document ...
AMTH142 Practical 3
Copyright � 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit,
University of Leeds.
Copyright � 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie
University, Sydney.