This guide will teach us how to compute the solution of the nonlinear equations system in MATLAB using the fsolve() function.
How to Solve the Nonlinear Equations System in MATLAB?
The fsolve() is a built-in function in MATLAB used for solving a system of nonlinear equations with multiple variables. If the number of equations is the same as the number of unknowns, the solution of a system of nonlinear equations will be numerical; otherwise, the solution will be symbolic in terms of the desired variable. Each variable in the system of nonlinear equations can have one or multiple solutions based on its order.
Syntax
The fsolve() function follows a simple syntax to solve a system of nonlinear equations in MATLAB.
x = fsolve(fun,x0,options)
Here:
The function x = fsolves(fun, x0) solves the system of nonlinear equations starting from point x0.
The function x = fsolves(fun, x0, options) solves the nonlinear system of equations using optimization methods specified in the options.
Note: The options by default use the Newton Rapson method to compute solutions of systems of nonlinear equations. You can specify other methods, such as trust region, Levenberg-Marquardt, and others.
Examples
Follow the given examples to learn how to solve a system of nonlinear equations using the fsolve() function in MATLAB.
Example 1: Solving 2 Nonlinear Equations in MATLAB
The given example first creates a MATLAB user-defined function named nonlinear_system containing the system of two nonlinear equations.
Now we call the function in another script file to solve the defined system of nonlinear equations using the fsolve(fun, x0) function starting from the point x0 = (0, 0).
x0 = [0,0];
x = fsolve(fun,x0)
Example 2: Solving Nonlinear Equations Starting from Point [-5,5]
Now consider the defined system of equations in the user-defined function file nonlinear_system.m and call the function to solve that system of nonlinear equations starting from the point x0 = [-5, 5] using the fsolve() function.
x0 = [-5,5];
x = fsolve(fun,x0)
For more details, read this guide.
Conclusion
Solving a system of nonlinear equations is the most common problem in mathematics and engineering. MATLAB provides us with a built-in fsolve() function that allows us to solve a system of nonlinear equations. This guide has covered the basics of solving systems of nonlinear equations that will help beginners understand the working of fsolve() function in MATLAB.