Difference between revisions of "Octave"
Dinas-emrys (talk | contribs) (→Octave) |
Dinas-emrys (talk | contribs) (Added console line formatting and text to example.) |
||
Line 6: | Line 6: | ||
{{Prepare WWW Directory}} | {{Prepare WWW Directory}} | ||
== Graphing == | == Graphing == | ||
Octave may be started by typing 'octave' in the shell. It's easiest to perform this in your '''www''' directory so the files that you create will be saved there. | |||
{{ConsoleLine|liang-xue@codermerlin:~$|cd ~/www}} | |||
{{ConsoleLine|liang-xue@codermerlin:~$|octave}} | |||
You'll know you're in Octave when you see the Octave prompt. | |||
{{ConsoleLine|octave:1>|}} | |||
In order to enable graphics plotting, execute the following command: | |||
{{ConsoleLine|octave:1>|graphics_toolkit("gnuplot")}} | |||
We'll begin with a 3-D example to demonstrate the power of Octave and the ease with which complex graphs can be created. | |||
== Examples == | == Examples == | ||
=== 3-D Sombrero Plot === | === 3-D Sombrero Plot === | ||
{{ConsoleLine|octave:2>|tx {{Equal}} ty {{Equal}} linspace (-8, 8, 41)';}} | |||
tx | {{ConsoleLine|octave:3>|[xx, yy] {{Equal}} meshgrid (tx, ty);}} | ||
[xx, yy] | {{ConsoleLine|octave:4>|r {{Equal}} sqrt (xx .^ 2 + yy .^ 2) + eps;}} | ||
r | {{ConsoleLine|octave:5>|tz {{Equal}} sin (r) ./ r;}} | ||
tz | {{ConsoleLine|octave:6>|mesh (tx, ty, tz);}} | ||
mesh (tx, ty, tz); | {{ConsoleLine|octave:7>|xlabel ("tx");}} | ||
xlabel ("tx"); | {{ConsoleLine|octave:8>|ylabel ("ty");}} | ||
ylabel ("ty"); | {{ConsoleLine|octave:9>|zlabel ("tz");}} | ||
zlabel ("tz"); | {{ConsoleLine|octave:10>|title ("3-D Sombrero plot");}} | ||
title ("3-D Sombrero plot"); | We can now print the plot to a file with: | ||
{{ConsoleLine|octave:11>|print -dpng sombrero.png}} | |||
It may take a few seconds to produce the file; be patient. When the prompt returns, the file may be viewed in a browser. | |||
== References == | == References == | ||
<references/> | <references/> |
Revision as of 16:18, 26 March 2022
Octave[edit]
GNU Octave is software featuring a high-level programming language, primarily intended for numerical computations. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with MATLAB.[1]
Preparation[edit]
In this exercise, you'll be generating graphic files by using Octave. In order to view these files, you'll save them in a special directory called "~www" which must be created in your home directory. The following instructions will instruct you on how to create this directory.
Create a directory to be served by the web server. If the directory already exists, no error will occur.
amrit-gupta@codermerlin:~$ mkdir --parents ~/www
Enter the directory.
amrit-gupta@codermerlin:~$ cd ~/www
Set the permissions so that the files can be accessed by the web server. If permission errors are encountered, re-execute this command.
amrit-gupta@codermerlin:~$ chmod -R a+rX ~/www
Graphing[edit]
Octave may be started by typing 'octave' in the shell. It's easiest to perform this in your www directory so the files that you create will be saved there.
liang-xue@codermerlin:~$ cd ~/www
liang-xue@codermerlin:~$ octave
You'll know you're in Octave when you see the Octave prompt.
octave:1>
In order to enable graphics plotting, execute the following command:
octave:1> graphics_toolkit("gnuplot")
We'll begin with a 3-D example to demonstrate the power of Octave and the ease with which complex graphs can be created.
Examples[edit]
3-D Sombrero Plot[edit]
octave:2> tx = ty = linspace (-8, 8, 41)';
octave:3> [xx, yy] = meshgrid (tx, ty);
octave:4> r = sqrt (xx .^ 2 + yy .^ 2) + eps;
octave:5> tz = sin (r) ./ r;
octave:6> mesh (tx, ty, tz);
octave:7> xlabel ("tx");
octave:8> ylabel ("ty");
octave:9> zlabel ("tz");
octave:10> title ("3-D Sombrero plot");
We can now print the plot to a file with:
octave:11> print -dpng sombrero.png
It may take a few seconds to produce the file; be patient. When the prompt returns, the file may be viewed in a browser.
References[edit]
- ↑ Gnu Octave. (2022, February, 10). In Wikipedia. https://en.wikipedia.org/wiki/GNU_Octave