## Octave – inizio – 3 Continuo da qui i primi esempi di Octave, seguendo il manuale, qui.

Soluzione di sistemi di equazioni lineari
Systems of linear equations are ubiquitous in numerical analysis. To solve the set of linear equations `Ax = b`, use the left division operator, ‘`\`’:

`x = A \ b`

This is conceptually equivalent to `inv (A) * b`, but avoids computing the inverse of a matrix directly.

If the coefficient matrix is singular, Octave will print a warning message and compute a minimum norm solution.

A simple example comes from chemistry and the need to obtain balanced chemical equations. Consider the burning of hydrogen and oxygen to produce water.

`H2 + O2 → H2O`

Nota: `→` lo ottengo con AltGr+i
The equation above is not accurate. The Law of Conservation of Mass requires that the number of molecules of each type balance on the left- and right-hand sides of the equation. Writing the variable overall reaction with individual equations for hydrogen and oxygen one finds:

```x1*H2 + x2*O2 → H2O H: 2*x1 + 0*x2 → 2 O: 0*x1 + 2*x2 → 1```

The solution in Octave is found in just three steps: Integrare equazioni differenziali
Octave has built-in functions for solving nonlinear differential equations of the form with the initial condition For Octave to integrate equations of this form, you must first provide a definition of the function `f(x,t)`. This is straightforward, and may be accomplished by entering the function body directly on the command line. For example, the following commands define the right-hand side function for an interesting pair of nonlinear differential equations. Note that while you are entering a function, Octave responds with a different prompt, to indicate that it is waiting for you to complete your input. Given the initial condition

`x0 = [1; 2];`

and the set of output times as a column vector (note that the first output time corresponds to the initial condition given above)

`t = linspace (0, 50, 200)';`

it is easy to integrate the set of differential equations: oops! ma nel frame Spazio di lavoro ho Sono completamente all’oscuro di cosa sto trattando, il manuale dice che [t]he function `lsode` uses the Livermore Solver for Ordinary Differential Equations, described in A. C. Hindmarsh, ODEPACK, a Systematized Collection of ODE Solvers, in: Scientific Computing, R. S. Stepleman et al. (Eds.), North-Holland, Amsterdam, 1983, pages 55–64.
La Wiki conosce `lsode`, e cita –indovina?– Octave 😀

Creare un output grafico
To display the solution of the previous example graphically, use the command

`plot (t, x)`

If you are using a graphical user interface, Octave will automatically create a separate window to display the plot. To save a plot once it has been displayed on the screen, use the print command. For example,

`print -dpdf foo.pdf`

yesss, produce come previsto il file `foo.pdf`, lamentandosi però: In alternativa alla creazione del PDF conviene salvare il plot; io l’ho salvato come `.png`, funziona; mi sa che si approfondirà a suo tempo.

Ecco la stessa cosa nella REPL: Uh! ecco una cosa che dovevo leggere: The command `help print` explains more options for the `print` command and provides a list of additional output file formats. No, il solito errore: `sh: 1: most: not found`, da fissare 😦 Pausa 😀 Posta un commento o usa questo indirizzo per il trackback.