Solve nonlinear equations (advanced)
Coding nonlinear algebraic equations.
Equation for circle:  x2  +  y2  =  R2
Equation for sine curve:  y  =  A * sin(x)
To write a MATLAB® code to numerically solve for x and y for  1 ≤ R ≤ 3,type
Constant R % Radius of circle. Constant A = 1 meter % Amplitude of sine wave. Variable x, y Eqn[1] = x^2 + y^2 - R^2 % Circle: x^2 + y^2 = R^2 Eqn[2] = y - A*sin(x) % Sine wave: y = A*sin(x) Input x = 3 meters, y = 3 meters Output R meters, x meters, y meters Nonlinear(Eqn = 0, x, y) [R = 1, 3, 0.5] MGSolveNonlinearEqns.m
MotionGenesis™ produces highly efficient and symbolically optimized codes.
C code
MGSolveNonlinearEqns.c
Compile and link source code.
Modify input values in MGSolveNonlinearEqns.in
Fortran code
MGSolveNonlinearEqns.f
Compile and link source code.
Modify input values in MGSolveNonlinearEqns.in
MATLAB®
MGSolveNonlinearEqns.m
Invoke MATLAB® and type MGSolveNonlinearEqns
Modify input values in MGSolveNonlinearEqns.m
One way to run this MATLAB® .m script is to open MATLAB® and click the "Browse For Folder" icon as shown below:
MatlabBrowseForFolderWithMFileA.png
Browse to your MotionGenesis folder, select it (single click), then click OK (or Open). The MotionGenesis folder name should appear in the textbox.
MatlabBrowseForFolderWithMFileB.png
In the MATLAB® command window, type MGSolveNonlinearEqns to produce:
% FILE: MGSolveNonlinearEqns.1
%
% Residual     R         x          y
% (UNITS)   (meters)  (meters)   (meters)

1.221E-15  1.00E+00  7.391E-01  6.736E-01
1.177E-14  1.50E+00  1.181E+00  9.249E-01
3.483E-13  2.00E+00  1.740E+00  9.857E-01
2.209E-13  2.50E+00  2.409E+00  6.689E-01
4.656E-15  3.00E+00  2.997E+00  1.446E-01
Continuous solution of one nonlinear algebraic equation.
Solve for y(t) for  0 ≤ t ≤ 20
y4 - 8*y - 0.3*t2 - 9*sin(t) = 0
MGSolveNonlinearEqnContinuouslyA.png
Continuous solution of two coupled nonlinear algebraic equations.
Solve for qA(t) and qB(t) for  0 ≤ t ≤ 2.2
  cos(qA) + 2*cos(qB) = 2 + 0.2*cos(t)
2*sin(qB) - sin(qA) = 0.3*sin(3*t)
Continuous solution of two coupled nonlinear algebraic.
Solve for r(t) and θ(t) for  0 ≤ t ≤ 7
x = r*cos(θ)   where   x = cos(1.2*t)
y = r*sin(θ)   where   y = sin(t)

MotionGenesis™ also does vector algebra, matrix algebra and solves sets of linear equations and ODEs (ordinary differential equations).
Simpler: Check out nonlinear equations basics.