MotionGenesis: F=ma Software, textbooks, training, consulting.      Solving one nonlinear algebraic equation

To numerically solve the equation    x^2 - cos(x) = 0,   type
  Variable  x
  Solve( x^2 - cos(x) = 0,   x = 0.2 )   % x = 0.2 is a guess.
  

As graphed to the right, this nonlinear equation has two solutions.
In general, nonlinear equations have an unknown number of solutions (0, 1, 2, 37, ...).
The   Solve   command frequently converges to a solution close to the starting guess.
If you guess   x = 0.2,     Solve   reports   x = 0.8241323
If you guess   x = -9,     Solve   reports   x = -0.8241323

To save input (for subsequent re-use) and/or input and output responses, type
Save   SolveSampleNonlinearEqn.txt
Save   SolveSampleNonlinearEqn.html

MotionGenesis graph of x^2 - cos(x) versus x



Solving sets of nonlinear algebraic equations

Equation for a circle:       x2  +  y2   =   1
Equation for a sine curve:       y   =   sin(x)

To numerically solve the previous set of nonlinear equations for x and y, type
Note: The arguments   x = 3   and   y = 5   are a guess for the solution.
  Variable x, y
  eqns[1] = x^2 +  y^2  -  1
  eqns[2] = y - sin(x)
  Solve( eqns = 0,   x = 3, y = 5 )
  
MotionGenesis Numerical solution for finding the intersection of a circle and sine-wave
These nonlinear equations have two solutions.
If you guess   x = 3,     y = 5,     Solve   reports   x = 0.739085   and   y = 0.673612
If you guess   x = -2,     y = -2,     Solve   reports   x = -0.739085   and   y = -0.673612

To save input (for subsequent re-use) and/or input and output responses, type
Save   SolveSampleNonlinearEqns.txt
Save   SolveSampleNonlinearEqns.html



Solving sets of nonlinear algebraic equations with input

Equation for a circle:       x2   +   y2   =   R2
Equation for a sine curve:       y   =   A * sin(x)

To numerically solve the previous set of nonlinear equations for x and y, type
  Constant  R = 1 meter,  A = 1 meter
  Variable  x, y
  Circle = x^2 +  y^2  -  R^2
  SineWave = y - A*sin(x)
  Solve( [Circle; SineWave] = 0,   x = 3, y = 5 )
  

To save input (for subsequent re-use) and/or input and output responses, type
Save   SolveSampleNonlinearEqnsWithInput.txt
Save   SolveSampleNonlinearEqnsWithInput.html

MotionGenesis Numerical solution for finding the intersection of a circle and sine-wave




Generating code to solve nonlinear algebraic equations

MotionGenesis produces highly efficient and symbolically optimized codes.
This short   script   shows how to generate various codes to solve the previous nonlinear equations.
Depending on your   license,   these deployable codes are independent of MotionGenesis.
Note: Each code outputs results in the file   CodeSampleNonlinearEqns.1

Code
Command file
Comments
C
CodeSampleNonlinearEqns.c Compile and link source code.
Modify input values in   CodeSampleNonlinearEqns.in
Note: Compiled code optimizes for its processor.
Fortran
CodeSampleNonlinearEqns.f Compile and link source code.
Modify input values in   CodeSampleNonlinearEqns.in
Note: Compiled code optimizes for its processor.
MATLABŪ
CodeSampleNonlinearEqns.m Invoke MATLABŪ and type   load CodeSampleNonlinearEqns
Modify input values in   CodeSampleNonlinearEqns.m
Note: Interpreted .m codes are slower than compiled codes.

To save input (for subsequent re-use) and/or input and output responses, type
Save   CodeSampleNonlinearEqns.txt
Save   CodeSampleNonlinearEqns.html