Saturday, December 8, 2007

Using Matlab for Higher Order ODEs and Systems of ODEs

Original document

(Continuation of Using Matlab for First Order ODEs)

Contents

Numerical Solution
Converting problems to first order systems
Plotting the solution
Finding numerical values at given t values
Making phase plane plots
Vector fields for autonomous problems
Plotting the vector field
Plotting the vector field together with solution curves
Symbolic Solution
Example with 2nd order problem
Plotting the solution
Finding numerical values at given t values
Example with first order system
Plotting the solution
Finding numerical values at given t values
Making phase plane plots

Numerical solution

Example problem: The angle y of an undamped pendulum with a driving force sin(5 t) satisfies the differential equation

y'' = -sin(y) + sin(5 t)

and the initial conditions

y(0) = 1
y'(0) = 0.

If your problem is of order 2 or higher: rewrite your problem as a first order system. Let y1=y and y2=y', this gives the first order system

y1' = y2,
y2' = -sin(y1) + sin(5 t)

with the initial conditions

y1(0) = 1
y2(0) = 0.

Define an inline function g for the right hand side of the first order system: Note that g must be specified as a column vector using [...;...] (not a row vector using [...,...]). In the definition of g, use y(1) for y1, use y(2) for y2. The definition of g should have the form

g = inline('[ expression for y1' ; expression for y2' ]', 't', 'y');

You have to use inline(...,'t','y'), even if t does not occur in your formula. For our example the first component of g is y2, the second component is -sin(y1) + sin(5 t) and we define

g = inline('[ y(2); -sin(y(1))+sin(5*t) ]', 't', 'y')

To plot the numerical solution: To obtain plots of all the components of the solution for t going from t0 to t1 use ode45(g,[t0,t1],[y10;y20]) where y10, y20 are the initial values for y1, y2 at the starting point t0. In our example we get a plot for t going from 0 to 20 with the initial values [1;0] using

ode45(g,[0,20],[1;0])

This shows the two functions y1(t)=y(t) (blue) and y2(t)=y'(t) (green).

The circles mark the values which were actually computed (the points are chosen by Matlab to optimize accuracy and efficiency). You can obtain a vector ts and a matrix ys with the coordinates of these points using [ts,ys] = ode45(g,[t0,t1],[y10;y20]). You can then plot the solution curves using plot(ts,ys) (this is a way to obtain a plot without the circles). Note that each row of the matrix ys contains 2 entries corresponding to the two components of the solution at that time:

[ts,ys] = ode45(g,[0,20],[1;0]); % find ts, ys, but don't show
plot(ts,ys) % make plot of y1 and y2 vs. t
[ts,ys] % show table with 3 columns for t, y1, y2

You can obtain the vector of y1 values in the first column of ys by using ys(:,1), therefore plot(ts,ys(:,1)) plots only y1(t).

To obtain numerical values at specific t values: You can specify a vector tv of t values and use [ts,ys] = ode45(g,tv,[y10;y20]). The first element of the vector tv is the initial t value; the vector tv must have at least 3 elements. E.g., to obtain the solution with the initial values [1;0] at t = 0, 0.5, ..., 10 and display the results as a table with 3 columns t, y1, y2, use

[ts,ys]=ode45(g,0:0.5:10,[1;0]);
[ts,ys]

To plot trajectories in the phase plane: To see the points with coordinates ( y1(t), y2(t) ) in the y1, y2 plane for t going from 0 to 20 type

options=odeset('OutputFcn','odephas2');
ode45(g,[0,20],[1;0],options)

This shows the points while they are being computed (the plotting can be stopped with the stop button). To first compute the numerical values and then plot the curve without the circles, type

[ts,ys] = ode45(g,[0,20],[1;0]); % find ts, ys, but don't show
plot(ys(:,1),ys(:,2)) % make plot of y2 vs. y1

Vector fields for autonomous systems of two first order ODEs

If the right hand side function g(t, y) does not depend on t, the problem is called autonomous. In this case the behavior of the differential equation can be visualized by plotting the vector g(t, y) at each point y = (y1,y2) in the y1,y2 plane (the so-called phase plane).

First save the files vectfield.m and vectfieldn.m into the same directory where your m-files are.

To plot the vector field for y1 going from a1 to b1 with a spacing of d1 and y2 going from a2 to b2 with a spacing of d2 use vectfield(g,a1:d1:b1,a2:d2:b2). The command vectfieldn works in the same way, but produces arrows which all have the same length. This makes it easier to see the direction of the vector field.

Example: The undamped pendulum problem without a driving force has the differential equation y'' = -sin(y). This gives the first order system

y1' = y2,
y2' = -sin(y1)

Here we define

g = inline('[y(2);-sin(y(1))]','t','y')

We can plot the vector field and 10 trajectories with starting points (0,0), (0,0.3), ..., (0,2.7) in the phase plane as follows:

vectfield(g,-2:.5:8,-2.5:.25:2.5)
hold on
for y20=0:0.3:2.7
[ts,ys] = ode45(g,[0,10],[0;y20]);
plot(ys(:,1),ys(:,2))
end
hold off

Symbolic solution

Use the dsolve command. Specify all differential equations as strings, using Dy for y'(t), D2y for y''(t) etc. .

For an initial value problem specify the initial conditions in the form 'y(t0)=y0', 'Dy(t0)=y1' etc. . The last argument of dsolve is the name of the independent variable, e.g., 't'.

Example: For the differential equation

y'' = -y + sin(5 t)

use

sol = dsolve('D2y = -y + sin(5*t)','t')

In this case, the answer can be simplified by typing

s = simple(sol)

which gives the general solution -1/24*sin(5*t)+C1*cos(t)+C2*sin(t) with two constants C1, C2.

To solve the ODE with initial conditions y(0) = 1, y'(0) = 0 use

sol = dsolve('D2y = -y + sin(5*t)','y(0)=1','Dy(0)=0','t')

Then s = simple(sol) gives the solution -1/24*sin(5*t)+5/24*sin(t)+cos(t).

To plot the solution curve use ezplot:

ezplot(sol, [0,20])

To obtain numerical values at one or more t values proceed exactly as in the case of a first order ODE.

Example for system of ODEs: For the system

y1' = y2,
y2' = -y1 + sin(5 t)

with the initial conditions

y1(0) = 1
y2(0) = 0

type

sol = dsolve('Dy1=y2','Dy2=-y1+sin(5*t)','y1(0)=1','y2(0)=0','t')

which gives the somewhat strange response

sol =
y1: [1x1 sym]
y2: [1x1 sym]

This means that the two components of the solution can be accessed as sol.y1 and sol.y2 : Typing

sol.y1

gives -2/3*sin(t)*cos(t)^4+1/2*sin(t)*cos(t)^2+1/6*sin(t)+cos(t). This can be simplified by typing

s1 = simple(sol.y1)

which gives -1/24*sin(5*t)+5/24*sin(t)+cos(t). For the second component y2 of the solution we proceed in the same way: Typing

s2 = simple(sol.y2)

gives -sin(t)-5/24*cos(5*t)+5/24*cos(t).

To plot the solution curves use ezplot:

ezplot(sol.y1, [0,20])
hold on
ezplot(sol.y2, [0,20])
hold off

To obtain numerical values use double(subs(sol.y1,'t',tval)) where tval is a number or a vector of numbers. E.g., the following commands generate a table with three columns t, y1, y2 for t=0, 0.5, ..., 10:

tval = (0:0.5:10)'; % column vector with t-values
yval = double(subs([sol.y1,sol.y2],'t',tval)); % 2 columns with y1,y2
[tval, yval] % display 3 columns together

To plot the solution in the phase plane use a similar approach with more t values:

tval = (0:0.1:10)'; % column vector with t-values
yval = double(subs([sol.y1,sol.y2],'t',tval)); % 2 columns with y1,y2
plot(yval(:,1),yval(:,2)) % plot col.2 of yval vs. col.1 of yval


MATH 246 course page

Tobias von Petersdorff

Using Matlab for First Order ODEs

Original documents

Contents

Inline functions
Direction fields
Numerical solution of initial value problems
Plotting the solution
Combining direction field and solution curves
Finding numerical values at given t values
Symbolic solution of ODEs
Finding the general solution
Solving initial value problems
Plotting the solution
Finding numerical values at given t values

Inline Functions

If you want to use a function several times it is convenient to define it as a so-called inline function:

f1 = inline('sin(x)*x','x')

defines the function f1(x)=sin(x)*x. Note that the arguments of inline must be strings (not symbolic expressions). You can then use the function f1 in expressions you type in.

You can also define inline functions of several variables:

g1 = inline('x*y+sin(x)','x','y')

defines the function g1(x,y)=x*y+sin(x) of two variables.

Direction Fields

First download the file dirfield.m and put it in the same directory as your other m-files for the homework.

Define an inline function g of two variables t, y corresponding to the right hand side of the differential equation y'(t) = g(t,y(t)). E.g., for the differential equation y'(t) = t y2 define

g = inline('t*y^2','t','y')

You have to use inline(...,'t','y'), even if t or y does not occur in your formula.

To plot the direction field for t going from t0 to t1 with a spacing of dt and y going from y0 to y1 with a spacing of dy use dirfield(g,t0:dt:t1,y0:dy:y1). E.g., for t and y between -2 and 2 with a spacing of 0.2 type

dirfield(g,-2:0.2:2,-2:0.2:2)

Solving an initial value problem numerically

First define the inline function g corresponding to the right hand side of the differential equation y'(t) = g(t,y(t)). E.g., for the differential equation y'(t) = t y2 define

g = inline('t*y^2','t','y')

To plot the numerical solution of an initial value problem: For the initial condition y(t0)=y0 you can plot the solution for t going from t0 to t1 using ode45(g,[t0,t1],y0).

Example: To plot the solution of the initial value problem y'(t) = t y2, y(-2)=1 in the interval [-2,2] use

ode45(g,[-2,2],1)

The circles mark the values which were actually computed (the points are chosen by Matlab to optimize accuracy and efficiency). You can obtain vectors ts and ys with the coordinates of these points using [ts,ys] = ode45(g,[t0,t1],y0). You can then plot the solution using plot(ts,ys) (this is a way to obtain a plot without the circles).

To combine plots of the direction field and several solution curves use the commands hold on and hold off: After obtaining the first plot type hold on, then all subsequent commands plot in the same window. After the last plot command type hold off.

Example: Plot the direction field and the 13 solution curves with the initial conditions y(-2) = -0.4, -0.2, ..., 1.8, 2:

dirfield(g,-2:0.2:2,-2:0.2:2)
hold on
for y0=-0.4:0.2:2
[ts,ys] = ode45(g,[-2,2],y0); plot(ts,ys)
end
hold off

To obtain numerical values of the solution at certain t values: You can specify a vector tv of t values and use [ts,ys] = ode45(g,tv,y0). The first element of the vector tv is the initial t value; the vector tv must have at least 3 elements. E.g., to obtain the solution with the initial condition y(-2)=1 at t = -2, -1.5, ..., 1.5, 2 and display the results as a table with two columns, use

[ts,ys]=ode45(g,-2:0.5:2,1);
[ts,ys]

To obtain the numerical value of the solution at the final t-value use ys(end) .

Solving a differential equation symbolically

You have to specify the differential equation in a string, using Dy for y'(t) and y for y(t): E.g., for the differential equation y'(t) = t y2 type

sol = dsolve('Dy=t*y^2','t')

The last argument 't' is the name of the independent variable. Do not type y(t) instead of y.

If Matlab can't find a solution it will return an empty symbol. If Matlab finds several solutions it returns a vector of solutions.

Sometimes Matlab can't find an explicit solution, but returns the solution in implicit form. E.g., dsolve('Dy=1/(y-exp(y))','t') returns

t-1/2*y^2+exp(y)+C1=0

Unfortunately Matlab cannot handle initial conditions in this case. You can use ezcontour('t-1/2*y^2+exp(y)',[-4 4 -3 3]) to plot several solution curves for t in [-4,4], y in [-3,3]. You can use ezplot('t-1/2*y^2+exp(y)-1',[-4 4 -3 3]) to plot only the curve where t-1/2*y^2+exp(y)=1.

The solution will contain a constant C1. You can substitute values for the constant using subs(sol,'C1',value). E.g., to set C1 to 5 and plot this solution for t=-2 to 2 use

ezplot( subs(sol,'C1',5) , [-2 2] )

To solve an initial value problem additionally specify an initial condition:

sol = dsolve('Dy=t*y^2','y(-2)=1','t')

To plot the solution use ezplot(sol,[t0,t1]). Here is an example for plotting the 13 solution curves with the initial conditions y(-2) = -0.4, -0.2, ..., 1.8, 2:

sol = dsolve('Dy=t*y^2','y(-2)=y0','t')
for y0=-0.4:0.2:2
ezplot( subs(sol,'y0',y0) , [-2 2])
hold on
end
hold off
axis tight

To obtain numerical values at one or more t values use subs(sol,'t',tval) and double (or vpa for more digits):

sol = dsolve('Dy=t*y^2','y(-2)=1','t')

This gives a numerical value of the solution at t=0.5:

double( subs(sol,'t',0.5) )

This computes numerical values of the solution at t=-2, -1.5, ..., 2 and displays the result as a table with two columns:

tval = (-2:0.5:2)'; % column vector with t-values
yval = double( subs(sol,'t',tval) )% column vector with y-values
[tval,yval] % display 2 columns together


(continued in Using Matlab for Higher Order ODEs and Systems of ODEs)

MATH 246 course page

Tobias von Petersdorff

Tuesday, October 9, 2007

Basic Matrix, collected

17.1 Basic Matrix Functions, from GNU Octave Manual by John W. Eaton


Octave Examples for Solving Linear Algebra Equations, from Hanson's website.

Note: very useful for the Intro to Numerical Analysis course.


Bad Octave/Matlab 1-norm! The 1-norm is not the regular one!

Monday, October 8, 2007

Basic Plotting

Plotting set of points (vector)

angles = [o:pi/3:2*pi]
y = sin(angles)
plot(angles, y)


Plot smoother curves (vector)


angles = linspace(0, 2*pi, 100) % 100 points equally spaced btw 0 and 2pi
y = sin(angles)
plot(angles, y)

Basic options
'.' = Set dots plot style
'@' = Set points plot style
'-@' = Set linespoints plot style
'^' = Set impulses plot style
'L' = Set steps plot style
'N' = Interpreted as the plot color if N is an integer in the range 1 to 6
'NM' = if N an integer in the range 1 to 6 -> color
if M an integer in the range 1 to 6 -> point style
This is only valid in combination with the '@' or '-@' specifier
'C' = plot color
'";title;"' = here '"title"' is the label for the key

1 = red / *
2 = greed / +
3 = blue / o
4 = magenta / x
5 = cyan / house
6 = brown / there exists

Example:

plot(x, y, "@12", x, y2, x, y3, "4", x, y4, "+"), This command plot
'y' with color 1 (red) and points of type 2 (+),
'y2' with lines
'y3' with lines of color 4 (magenta)
'y4' with points displayed as '+'

plot(b, '*'), plot the data in the var. b w. points displayed as '*'.

t = 0:0.1:6.3;
plot(t, cos(t), "-;cos(t);", t, sin(t), "+3; sin(t);")



Title and Labels

title('Graph of y = sin(x)')
xlabel('Angle')
ylabel('Value')


Colors and Styles
for symbols and lines in the plot command (see help plot)
(M = only available in Matlab)

w = white
m = magneta
c = cyan
r = red
g = green
b = blue
y = yellow
k = black

. = point
o = circle
x = x-mark
+ = plus
* = star
s = square (M)
d = diamond (M)
v = triangle (down) (M)
^ = triangle (up) (M)
< = triangle (left) (M)
> = triangle (right) (M)
p = pentagram (M)
h = hexagram (M)

- = solid
: = dotted (M)
-. = dashdot (M)
-- = dashed (M)


Extra

grid on % turn on grid
grid off
hold on % keep current plot to add more
hold off
figure (N) % plot graph in window N. If no number is specified, the next number is called. If command not called, graph will be plotted in exactly the same window.

More info:
1) plot is the user-defined function from the file /usr/share/octave/2.9.9/m/plot/plot.m
2) Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc ' to search the manual index.
3) See also: semilogx, semilogy, loglog, polar, mesh, contour,
__pltopt__ bar, stairs, errorbar, replot, xlabel, ylabel, title,
print.

Sunday, October 7, 2007

Basic Functions

cos : cosin of an angle (in radians)
sin : sin of an angle (in radians)
tan : tan of an angle (in radians)
exp : exponential function
log : natural logarithm
log10 : logarithm to base 10
sinh : hyperbolic sine
cosh : hyperbolic cosine
tanh : hyperbolic tanh
acos : inverse cosine
asin : inverse sine
atan : inverse tan
atan2 : two-argument form of inverse tan
atanh : inverse tanh

abs
sign
round
: round to the nearest integer
floor : round down (towards minus infinity)
ceil : round up (towards plus infnity)
fix : round towards zero
rem : remainder after integer division

Function Programming

BASIC

1. Function is defined in a text file, just like a script, exept that the first line has the following form:

function [output1, output2, ... ] = name ( input1, input2, ... )

2. Each function is stored in a different M-file, which MUST HAVE THE SAME NAME AS THE FUNCTION.
i.e., a function called sind() must be defined in a file called sind.m

EXAMPLE 1. Sine in degrees

function s = sind(x)
%SIND(X) Calculates sine(x) in degrees
s = sin(x*pi/180);

Line 1: Tells OCTAVE that this file defines a function.
- The function is called sind.
- It takes one argument, called x.
- The result is to be known, internally, as s.
- Whatever s is set to in this function is what the user will get when they use the sind function

Line 2: Is a comment line.
- The first set of comments in the file should discribe the function.
- This line is the one printed when the user types 'help sind'.
- It is usual to use a similar format to that which is used by Octave's built-in functions.

Line 3: Does the actual work in this function. ...

End of the function
- Functions in Octave do not need to end with 'return'
- (although you can use the 'return' command to make Octave jump out of a function in the middile)
- B/c each function is in a separate M-file, once it reached the end of the file, Octave knows that it is the end of the function.
- The value that s has at the end of this function is the value that is returned.

EXTRA
- The function AUTOMATICALLY works with vectors:
If you call the sind function with a vector, it means that the x parameter inside the function will be a vector.
In this case, the sin function knows how to work with vectors, so can give the correct response.

Example 2: Unit step
Here is a more sophisticated function which generates a unit step, defined as:
y = 0 if t < t0, 1 otherwise.

function y = ustep(t, t0)
%USTEP(t, t0) unit step at t0
% A unit step is defined as
% 0 for t <>
% 1 for t >= t0
[m,n] = size(t);
% Check that this is a vector, not a matrix i.e. (1 x n) or (m x 1)
if m ~= 1 & n ~= 1
error('T must be a vector');
end
y = zeros(m, n); %Initialise output array
for k = 1:length(t)
if t(k) >= t0
y(k) = 1; % Otherwise, leave it at zero, which is correct
end
end


Line 1: The first line says that
- this function is called ustep
- the user must supply two arguments (known internally as t and t0)
- the result of the function is one variable, called y

Line 2-5: Description of the function.
- This time the help message contains several lines.

Line 6-12:
- The error function print out a message and aborts the function if there is a problem.
- The length function tells us how many elements there are in the vector t

Extra:
We can use this function to create signal.
For example, to create a unit pulse of duration one second, starting at t = 0:

t = -1:0.1:4; % Define a time scale
v = ustep(t,0) - ustep(t,1)
plot(t,v)
axis([-1 4 -1 2])

This should display the pulse.. If we then type

who

We'll get:

*** dynamically linked functions:

dispatch
*** currently compiled function:

_ptl2_ _plt_ isscalar isvector rows
_ptl2vv_ axis isstr plot ustep

*** local user variables:

t v

Basic Symbols

Boolean expression

Symbol meaning example
== equal if x==y
~= not equal if x~=y
> greater than if x>y
>=
<
<=

& AND if x==y & y>2
| OR if x==1 | y>2
~ NOT if x = ~y

Vectors

Creating Vectors
a=[1 4 5] % row vector
a=[1;4;5] % column vector
d=[a 6] % add 6 at the end of vector a

a= 1:6 % row vector, value from 1 to 6, increment 1
b= 1:.3:6 % row vector, value from 1 to 6, increment .3

zeros(m,n) % create m x n matrix, all elements are 0
ones(m,n) %
create m x n matrix, all elements are 1
linspace(x1,x2,N) % create a vector of N elements,
% evenly spaced btw x1 and x2
logspace(x1,x2,N)
% create a vector of N elements,
% logarithmically spaced btw x1 and x2


a=[1:2:6 -1 0] gives: 1 3 5 -1 0

Extracting elements
a(3) % third element, result: 5
a(3:5) % elements from 3 to 5, result: 5 -1 0
a(1:2:5) % elements from 1 to 5 w. increment 2, result: 1 5 0


Vector maths
b=[1,2,3,4,5]

a*2 % regular scalar multiplication
a.*b % element-by-element multiplication
a./b % element-by-element division
% '.' means element-by-element
b.^2 % square each element of b, result: [1,4,9,16,25]
2.^b % raise 2 to each of the powers given in b, result: result: [2,4,8,16,32]

Control Statements

To cancel a command: Ctrl C

if ... else ...
if expression
statement
else if expression
statement
else
statement
end
end

Note:
1. The brackets () are not needed around the expression
2. The block of statement does not need to be delimited by the braces {}
3. The end command is used to mark the end of the script statement.

switch selection
switch x
case x1
statements
case x2
statements
otherwise
statements
end

or, similarly
switch x
case x1, statements
case x2, statements
otherwise, statements
end

for loops
for variable = vector
statements
end

Ex:
for n=1:5
nf(n) = factorial(n);
end

disp(nf)

while loops
while expression
statements
end

Install gnuplot on Ubuntu

Copied from Miscellaneous Debris

********************************************

Though there is gnuplot available in the Ubuntu/Debian repositories, there are reasons to compile gnuplot - first and most important gnu readline support! I don’t know why Debian maintainers don’t compile the GNU readline support into GNUplot - it’s some license issues - but it’s like that and this makes gnuplot practically unusable. Second having the pdf and wxWidgets terminal is not that bad at all :)

So here are the instructions:

First we compile and install wxWidgets

  • Download wxWidgets GTK 2.8.3
  • Untar it somewhere: tar xzf wxGTK-2.8.3.tar.gz
  • cd cd wxGTK-2.8.3/
  • mkdir buildgtk
  • cd buildgtk
  • ../configure
  • make
  • sudo paco -lp wxGTK-2.8.3 make install (or just make install if you don’t use paco)
  • sudo ldconfig (you may need to add /usr/local/lib to the file /etc/ld.so.conf before)

Than we are going to install the PDFlib lite

  • Download PDFlib Lite
  • tar xzf PDFlib-Lite-7.0.1.tar.gz
  • cd PDFlib-Lite-7.0.1
  • ./configure
  • make
  • sudo paco -lD make install
  • sudo ldconfig

Than we compile gnuplot

  • Download gnuplot 4.2
  • tar xzf gnuplot-4.2.0.tar.gz
  • cd gnuplot-4.2.0
  • ./configure –with-readline=gnu (check if we have the lines “pdf terminal: yes” and “wxt terminal: yes (EXPERIMENTAL)”, if you miss the jpeg, png and gif terminal install the libgd2-xpm-dev package; also check if you find “Readline library: GNU readline library with -lncurses”, if it says only minimal readline support than install the libreadline5-dev package; you need also the libx11-dev and libxt-dev package for the X11 terminal - libxt-dev package is normally not installed by default (at the debian page about gnuplot one can find the packages necessary to build gnuplot))
  • make (if you have problems here with some latex errors than disable the latex tutorial during the configure stage with “–without-tutorial”, if you get a “103: makeinfo: not found” error message than install the texinfo package)
  • sudo paco -lD make install

Than you have gnuplot installed with nice readline support (command line like in bash), a nice new wxWidgets terminal and a pdf terminal.

Monday, September 24, 2007

Command Line Options

2.1.1 Command Line Options

Here is a complete list of all the command line options that Octave accepts.

--debug
-d
Enter parser debugging mode. Using this option will cause Octave's parser to print a lot of information about the commands it reads, and is probably only useful if you are actually trying to debug the parser.
--echo-commands
-x
Echo commands as they are executed.
--eval code
Evaluate code and exit when done unless --persist is also specified.
--exec-path path
Specify the path to search for programs to run. The value of path specified on the command line will override any value of OCTAVE_EXEC_PATH found in the environment, but not any commands in the system or user startup files that set the built-in variable EXEC_PATH.
--help
-h
-?
Print short help message and exit.
--image-path path
Specify the path to search for images. The value of path specified on the command line will set the value of IMAGE_PATH found in the environment.
--info-file filename
Specify the name of the info file to use. The value of filename specified on the command line will override any value of OCTAVE_INFO_FILE found in the environment, but not any commands in the system or user startup files that use the info_file function.
--info-program program
Specify the name of the info program to use. The value of program specified on the command line will override any value of OCTAVE_INFO_PROGRAM found in the environment, but not any commands in the system or user startup files that use the info_program function.
--interactive
-i
Force interactive behavior. This can be useful for running Octave via a remote shell command or inside an Emacs shell buffer. For another way to run Octave within Emacs, see Emacs.
--no-history
-H
Disable command-line history.
--no-init-file
Don't read the ~/.octaverc or .octaverc files.
--no-line-editing
Disable command-line editing.
--no-site-file
Don't read the site-wide octaverc file.
--norc
-f
Don't read any of the system or user initialization files at startup. This is equivalent to using both of the options --no-init-file and --no-site-file.
--path path
-p path
Specify the path to search for function files. The value of path specified on the command line will override any value of OCTAVE_PATH found in the environment, but not any commands in the system or user startup files that set the internal load path through one of the path functions.
--persist
Go to interactive mode after --eval or reading from a file named on the command line.
--silent
--quiet
-q
Don't print the usual greeting and version message at startup.
--traditional
--braindead
For compatibility with Matlab, set initial values for user-preferences to the following values
            PS1                             = ">> "
PS2 = ""
beep_on_error = true
crash_dumps_octave_core = false
default_save_options = "-mat-binary"
fixed_point_format = true
history_timestamp_format_string = "%%-- %D %I:%M %p --%%"
page_screen_output = false
print_empty_dimensions = false

and disable the following warnings

            Octave:fopen-file-in-path
Octave:function-name-clash
Octave:load-file-in-path

--verbose
-V
Turn on verbose output.
--version
-v
Print the program version number and exit.
file
Execute commands from file. Exit when done unless --persist is also specified.

Octave also includes several built-in variables that contain information about the command line, including the number of arguments and all of the options.

— Built-in Function: argv ()

Return the command line arguments passed to Octave. For example, if you invoked Octave using the command

          octave --no-line-editing --silent

argv would return a cell array of strings with the elements --no-line-editing and --silent.

If you write an executable Octave script, argv will return the list of arguments passed to the script. See Executable Octave Programs, for an example of how to create an executable Octave script.

— Built-in Function: program_name ()

Return the last component of of the value returned by program_invocation_name.

    
See also: program_invocation_name.

— Built-in Function: program_invocation_name ()

Return the name that was typed at the shell prompt to run Octave.

If executing a script from the command line (e.g., octave foo.m) or using an executable Octave script, the program name is set to the name of the script. See Executable Octave Programs, for an example of how to create an executable Octave script.

    
See also: program_name.

Here is an example of using these functions to reproduce Octave's command line.

     printf ("%s", program_name ());
arg_list = argv ();
for i = 1:nargin
printf (" %s", arg_list{i});
endfor
printf ("\n");

See Index Expressions, for an explanation of how to properly index arrays of strings and substrings in Octave, and See Defining Functions, for information about the variable nargin.

Begin

Get help: help + whatever
Ex: help plot
help comma
help semicolon
More about comments for getting help.

Matrix
Identity 3x3 matrix: eye(3)
A 3x3 matrix: A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]
A random matrix w. coeffs. between 0 and 1: B = rand (3, 2)
To display B: B
Transpose: B'
Matrix arithmetics: 2*A, A*B, A'*A
Solve Linear System Ax=b: A\b

Integrating Differential Equations
To be continued.