Octave Example for Solving Set of Nonlinear Equations


MathLab> octave
Octave, version 1.1.1.
Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton.
This is free software with ABSOLUTELY NO WARRANTY.
For details, type `warranty'.

Solution of 1 Equation in 1 Unknown:

octave:1>  # Comment: Define Function:
octave:1>  function y = f (x)
>  y=x^3+x^2-3*x-3;
> endfunction

octave:2>  # Comment: Solve System for Root Starting at x0=+1.0:
octave:2> [x, info] = fsolve ("f", 1.)

x = 1.7321

info = 1

octave:3>  # Comment: Solve System for Root Starting at x0=0.0:
octave:3> [x, info] = fsolve ("f", 0.)

x = -1

info = 1

octave:3>  # Comment: Solve System for Root Starting at x0=-2.0:
octave:3> [x,info]=fsolve("f",-2.)
x = -1.7321

info = 1

octave:4> # Comment: Go to Next Problem:

Solution of 2 Equations in 2 Unknowns:

octave:4>  # Comment: Define Function:
octave:4>  function y = f (x)
>  y(1) = -2*x(1)^2 + 3*x(1)*x(2)   + 4*sin(x(2)) - 6;
> y(2) =  3*x(1)^2 - 2*x(1)*x(2)^2 + 3*cos(x(1)) + 4;
> endfunction

octave:5>  # Comment: Solve System for Vector Root Starting at [1; 2]:
octave:5> [x, info] = fsolve ("f", [1; 2])

x =

  0.57983
  2.54621

info = 1

Quit:

octave:22> quit

MathLab>



Web Source: http://www.math.uic.edu/~hanson/OctaveNonlinearEG.html

Email Comments or Questions to hanson@math.uic.edu