Breve, muito breve mesmo, introdução ao GNU/Octave
Última actualização: 2008-05-03 [16:50]
octave:1> help help help is a built-in command -- Command: help Octave's `help' command can be used to print brief usage-style messages, or to display information directly from an on-line version of the printed manual, using the GNU Info browser. If invoked without any arguments, `help' prints a list of all the available operators, functions, and built-in variables. If the first argument is `-i', the `help' command searches the index of the on-line version of this manual for the given topics. For example, the command `help help' prints a short message describing the `help' command, and `help -i help' starts the GNU Info browser at this node in the on-line version of the manual. Once the GNU Info browser is running, help for using it is available using the command `C-h'. Overloaded function dispatch_help(string,...) Additional help for built-in functions, operators, and variables is available in the on-line version of the manual. Use the command `help -i <topic>' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list.
octave:2> help exit exit is a built-in function -- Built-in Function: exit (STATUS) -- Built-in Function: quit (STATUS) Exit the current Octave session. If the optional integer value STATUS is supplied, pass that value to the operating system as the Octave's exit status. Additional help for built-in functions, operators, and variables is available in the on-line version of the manual. Use the command `help -i <topic>' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list.
octave:3> exit
Recomeçando
octave:1> help diary
diary is a built-in command --Command: diary options Create a list of all commands and the output they produce, mixed together just as you see them on your terminal. Valid options are: `on' Start recording your session in a file called `diary' in your current working directory. `off' Stop recording your session in the diary file. `FILE' Record your session in the file named FILE. Without any arguments, `diary' toggles the current diary state. Additional help for built-in functions, operators, and variables is available in the on-line version of the manual. Use the command `help -i <topic>' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list.
octave:2> diary
octave:3> 2+3 ans = 5 octave:4> 2*3 ans = 6 octave:5> 2/3 ans = 0.66667 octave:6> 1-4 ans = -3 octave:7>
octave:8> 1+2; octave:9>
octave:9> e e = 2.7183 octave:10> pi pi = 3.1416 octave:11> Inf Inf = Inf octave:12> true true = 1 octave:13> false false = 0 octave:14>
Formato longo (format long)
octave:14> pi pi = 3.1416 octave:15> format long octave:16> pi pi = 3.14159265358979 octave:17>
Formato curto (format short) ou simplesmente (format)
octave:17> format short octave:18> pi pi = 3.1416 octave:19>
Mostrar o o valor de x sem o "x=0"
octave:19> x=1 x = 1 octave:20> disp(x) 1 octave:21>ou ainda
octave:21> disp("O valor de pi igual a "),disp(pi)
O valor de pi igual a
3.1416
octave:22>
Um vector linha
octave:22> A=[1 2 3] A = 1 2 3 octave:23>um vector coluna
octave:23> B=[1;2;3] B = 1 2 3 octave:24>uma matriz
octave:24> C=[1 2 3;4 5 6; 7 8 9] C = 1 2 3 4 5 6 7 8 9 octave:25>
Matriz transposta A'
octave:25> A' ans = 1 2 3 octave:26>
Produto por um escalar
octave:26> m=2*A m = 2 4 6 octave:27>produto interno
octave:27> A*B ans = 14 octave:28>produtos de matrizes
octave:28> A*C ans = 30 36 42 octave:29> C*B ans = 14 32 50 octave:30>
octave:30> A^2 error: for A^b, A must be square error: evaluating binary operator `^' near line 30, column 2 octave:30>Operações sobre os elementos de uma matriz
octave:30> A.^2 ans = 1 4 9 octave:31>
Comece-se por definir a e. d. o. a estudar:
octave:1> function xdot = f(x,t) > xdot = -x; > endfunctionCalcular uma solução usando o algoritmo LSODE (Hindmarsh) no intervalo [0,1] com 50 pontos:
octave:2> x=lsode("f",2,(t=linspace(0,1,50)'));
e fazer o plot da solução
octave:3> plot(t,x)
Definindo o sistema:
octave:4> function xdot = f (x,t) > a=1; > b=1.4; > xdot(1) = x(2); > xdot(2) = -a*x(1)-b*x(2); > endfunctionresolvendo com condições iniciais x(1)=1 e x(2)=2 no intervalo [0,50] com 200 pontos
octave:5> x = lsode ("f", [1; 2], (t = linspace (0, 50, 200)'));
e fazer o plot
octave:6> plot(x,t)
1999-2008 (c) Tiago Charters de Azevedo São permitidas cópias textuais parciais/integrais em qualquer meio com/sem alterações desde que se mantenha este aviso.