Matlab

How to Use vpasolve() Function in MATLAB?

Solving an equation or a system of equations is a very common problem faced by mathematicians and engineers to solve real-life problems. We can analytically or numerically solve a single equation or the system of equations. Solving these equations analytically is easier than solving them numerically. The numerical methods require a large number of iterations to solve these equations which is complicated and time-consuming.

MATLAB is a high-performance programming language that can solve a single equation or a system of equations numerically in a small amount of time using the built-in vpasolve() function.

This blog will teach us how to solve the single equation or a system of equations in MATLAB using the vpasolve() function.

How to Implement the vpasolve() Function in MATLAB?

The vpasolve() function in MATLAB is a built-in function that enables us to solve a single equation or a system of equations numerically. This function accepts an equation or a system of equations and a set of independent variables as arguments and returns a numerical solution of the given equation or system of equations.

Syntax

The vpasolve() function uses different syntaxes in MATLAB:

Y = vpasolve(eqn,var)
Y = vpasolve(eqn,var,init_param)
Y = vpasolve(eqns,vars)
Y = vpasolve(eqns,vars,init_param)
[y1,...,yN] = vpasolve(eqns,vars)
[y1,...,yN] = vpasolve(eqns,vars,init_param)

 

Here:

The function Y = vpasolve(eqn,var) yields to solve the given equation eqn numerically with respect to the given variable var. If the variable is not specified, this function solves the equation for the default variable determined by syms.

The function Y = vpasolve(eqn,var,init_param) yields to solve the given equation eqn numerically with respect to the given variable var for the given initial guess init_param.

The function Y = vpasolve(eqns,vars) yields to numerically solve the given system of equations with respect to the given variables vars and returns a structure array Y containing the solutions of the given system of equations. If the variables are not specified, this function solves the system of equations for the default variables determined by syms.

The function Y = vpasolve(eqns,vars,init_param) yields to numerically solve the given system of equations with respect to the given variable vars for the given initial guess init_param.

The function [y1,…,yN] = vpasolve(eqns,vars) yields to numerically solve the given system of equations eqns with respect to the given variables vars and stores the solutions of the given system of equations in the variables y1, y2…yN. If the variables are not specified, this function solves the system of equations for the default variables determined by syms.

The function [y1,…,yN] = vpasolve(eqns,vars,init_param) yields to numerically solve the given system of equations eqns with respect to the given variable vars for the given initial guess init_param and stores the solutions of the given system of equations in the variables y1, y2…yN.

Examples

Follow the given examples to learn how to determine the solution of a single equation or a system of equations using the vpasolve() function in MATLAB.

Example 1: How to Use vpasolve() to Find the Solution of a Single Equation in MATLAB?

The given example uses the vpasolve() function to find the numerical solution of the given 5th-degree polynomial.

syms x
Y = vpasolve(5*x^5 - 3*x^2 + 3*x + 9 == 0, x)

 

Example 2: How to Use vpasolve() to Find the Solution of a Single Equation for the Initial Guess in MATLAB?

In this example, we find the numerical solution of the given 5th-degree polynomial for the initial guess using the vpasolve() function.

syms x
Y = vpasolve(5*x^5 - 3*x^2 + 3*x + 9 == 0, x, -1/2)

 

Example 3: How to Use vpasolve() to Find the Solution of a System of Equations in MATLAB?

The given MATLAB code uses the vpasolve() function to find the numerical solution of the given system of equations and returns a structure array Y containing the solutions of the variables x and y.

syms x y
Y = vpasolve([2*x^3 + 9*y == y, y^3 == x], [x,y])

 

Example 4: How to Use vpasolve() to Find the Solution of a System of Equations in MATLAB for the Initial Guess?

In this MATLAB code, we implement the vpasolve() function to find the numerical solution of the given system of equations for the given initial guess and return the solutions of the variables x and y.

syms x y
[x,y] = vpasolve([2*x^3 + 9*y == y, y^3 == x], [x,y], [-7,8])

 

Conclusion

Solving a single equation or a system of equations numerically is a complicated and time-consuming problem mostly faced by mathematicians and engineers. MATLAB facilitates us with a built-in vpasolve() function that enables us to numerically solve a single equation or a system of equations. This guide has covered how to solve a single equation or a system of equations in MATLAB using the vpasolve() function, allowing you to learn the art of using the function.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.