The following tutorials are an introduction to solving linear and nonlinear equations with MATLAB. The solution to linear equations is through matrix operations while sets of nonlinear equations require a solver to numerically find a solution.

% Create new file myFunction.m

function F=myFunction(z)

x = z(1);

y = z(2);

F(1)=x^2+y^2-20;

F(2)=y - x^2;

end

function F=myFunction(z)

x = z(1);

y = z(2);

F(1)=x^2+y^2-20;

F(2)=y - x^2;

end

% Create new file mySolver.m

clear all

zGuess = [1; 1];

z = fsolve(@myFunction, zGuess);

disp(z)

clear all

zGuess = [1; 1];

z = fsolve(@myFunction, zGuess);

disp(z)

Linear and nonlinear equations can also be solved with Excel and Python. Click on the appropriate link for additional information and source code.

The APMonitor Modeling Language with a MATLAB interface is optimization software for mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control. It is freely available through MATLAB, Python, Julia, or from a web browser interface.

comments powered by Disqus

Retrieved from http://apmonitor.com/che263/index.php/Main/MatlabSolveEquations

Page last modified on September 30, 2017, at 12:42 PM