**Support for character vector or string inputs has actually been removed. Instead, usage syms to explain variables and also replace inputs such as solve("2*x == 1","x") v solve(2*x == 1,x).You are watching: How to solve for a variable in matlab**

S = solve(eqn,var) solves the equation eqn because that the variable var. If you execute not specify var, the symvar duty determines the change to deal with for. For example, solve(x + 1 == 2, x) solves the equation *x*+1=2 for *x*.

S = solve(eqn,var,Name,Value) uses additional options mentioned by one or more Name,Value pair arguments.

Y = solve(eqns,vars) solves the mechanism of equations eqns because that the variables vars and also returns a framework that includes the solutions. If you carry out not clues vars, solve provides symvar to uncover the variables to settle for. In this case, the number of variables the symvar finds is same to the variety of equations eqns.

Y = solve(eqns,vars,Name,Value) uses added options specified by one or much more Name,Value pair arguments.

Solve the quadratic equation there is no specifying a variable to resolve for. Deal with chooses x to return the solution.

Return just real options by setup "Real" choice to true. The just real remedies of this equation is 5.

When deal with cannot symbolically solve an equation, the tries to uncover a numeric equipment using vpasolve. The vpasolve duty returns the first solution found.

Try addressing the adhering to equation. Fix returns a numeric solution since it cannot uncover a symbolic solution.

Plot the left and also the best sides that the equation. Observe the the equation additionally has a optimistic solution.

Find the other solution by straight calling the numeric solver vpasolve and specifying the interval.

When solving for multiple variables, it have the right to be more convenient to save the outputs in a structure variety than in different variables. The solve role returns a structure when you point out a single output argument and also multiple outputs exist.

Solve a mechanism of equations to return the solutions in a framework array.

Using a structure array enables you come conveniently instead of solutions into other expressions.

Use the subs function to substitute the solutions S right into other expressions.

The solve function can deal with inequalities and also return services that meet the inequalities. Fix the complying with inequalities.

Set "ReturnConditions" to true come return any kind of parameters in the solution and conditions ~ above the solution.

The parameters u and also v do not exist in MATLAB® workspace and also must be accessed using S.parameters.

Check if the worths u = 7/2 and also v = 1/2 meet the condition using subs and isAlways.

isAlways returns logical 1 (true) indicating that these values meet the condition. Substitute these parameter values right into S.x and S.y to discover a systems for x and y.

When solving for much more than one variable, the stimulate in which friend specify the variables specifies the bespeak in which the solver returns the solutions. Assign the solutions to variables solv and also solu by specifying the variables explicitly. The solver returns an array of remedies for every variable.

Return the complete solution of one equation with parameters and also conditions the the equipment by point out "ReturnConditions" as true.

Solve the equation sin(x)=0. Provide two extr output variables because that output disagreements parameters and also conditions.

The systems πk has the parameter k, whereby k should be one integer. The change k does no exist in MATLAB workspace and must be accessed using parameters.

Restrict the systems to 0x2π. Uncover a valid value of k because that this restriction. I think the condition, conditions, and also use settle to discover k. Instead of the value of k found into the equipment for x.

Alternatively, recognize the equipment for x by picking a value of k. Check if the value chosen satisfies the condition on k using isAlways.

Check if k=4 satisfies the condition on k.

isAlways return logical 1(true), definition that 4 is a valid worth for k. Substitute k through 4 to obtain a solution for x. Usage vpa to acquire a numeric approximation.

Solve the equation exp(log(x)log(3x))=4.

By default, resolve does not apply simplifications that space not valid because that all values of x. In this case, the solver does no assume the x is a optimistic real number, so the does not use the logarithmic identity log(3x)=log(3)+log(x). Together a result, settle cannot solve the equation symbolically.

Set "IgnoreAnalyticConstraints" to true to apply simplification rules the might enable solve to find a solution. Because that details, view Algorithms.

solve uses simplifications that permit the solver to discover a solution. The mathematical rules used when performing simplifications space not always valid in general. In this example, the solver uses logarithmic identities through the presumption that x is a optimistic real number. Therefore, the solutions discovered in this setting should be verified.

The sym and also syms features let you set assumptions because that symbolic variables.

Assume that the variable x is positive.

When you solve an equation for a variable under assumptions, the solver just returns solutions continuous with the assumptions. Settle this equation because that x.

For further computations, clean the presumption that you collection on the change x by recreating it utilizing syms.

When you fix a polynomial equation, the solver can use root to return the solutions. Solve a third-degree polynomial.

Try to get an explicit solution for such equations by calling the solver through "MaxDegree". The alternative specifies the maximum level of polynomials for which the solver tries to return clearly solutions. The default value is 2. Boosting this value, friend can obtain explicit remedies for higher order polynomials.

Solve the same equations for explicit solutions by increasing the worth of "MaxDegree" come 3.

Solve the equation sin(x)+cos(2x)=1.

Instead of returning an infinite collection of routine solutions, the solver choose three remedies that the considers to it is in the many practical.

Equation to solve, stated as a symbolic expression or symbolicequation. The relationship operator == definessymbolic equations. If eqn is a symbolic expression(without the ideal side), the solver assumes that the right side is0, and also solves the equation eqn == 0.

Variable because that which you settle an equation, stated as a symbolicvariable. By default, solve offers the variabledetermined by symvar.

System the equations, stated as symbolic expression or symbolicequations. If any kind of elements of eqns are symbolicexpressions (without the best side), deal with equatesthe facet to 0.

### vars — Variables for which you resolve an equation or system of equations symbolic vector | symbolic matrix

Variables for which you fix an equation or system of equations, specified as a symbolic vector or symbolic matrix. By default, solve supplies the variables figured out by symvar.

The stimulate in which friend specify this variables defines the orderin i m sorry the solver returns the solutions.

Flag because that returning just real solutions, stated as the comma-separated pair consists of "Real" and one of these values.

false | Return every solutions. |

true | Return just those solutions for i m sorry every subexpression of the original equation to represent a actual number. This option likewise assumes that all symbolic parameters of one equation represent genuine numbers. |

Flag for returning parameters in solution and conditions under i m sorry the systems is true, mentioned as the comma-separated pair consists of "ReturnConditions" and also one of this values.

false | Do no return parameterized solutions and the conditions under which the systems holds. The solve duty replaces parameters with ideal values. |

true | Return the parameters in the solution and also the conditions under which the solution holds. Because that a call with a single output variable, deal with returns a structure with the fields parameters and conditions. For multiple calculation variables, solve assigns the parameters and also conditions to the last two output variables. This behavior method that the variety of output variables have to be equal to the variety of variables to fix for plus two. |

See solve Inequalities.

**Example: **

### IgnoreAnalyticConstraints — leveling rules applied to expressions and equations false (default) | true

Simplification rules used to expressions and also equations, specifiedas the comma-separated pair consisting of "IgnoreAnalyticConstraints" andone of these values.

false | Use strictly simplification rules. |

true | Apply completely algebraic simplifications to expressions and equations. Setting IgnoreAnalyticConstraints come true can give you easier solutions, which can lead to results not usually valid. In various other words, this option applies mathematical identities that are convenient, but the results can not hold for all possible values of the variables. In part cases, that also permits solve to solve equations and also systems the cannot be fixed otherwise. |

See Shorten an outcome with leveling Rules.

### IgnoreProperties — Flag for returning remedies inconsistent v properties the variablesfalse (default) | true

Flag because that returning options inconsistent with the propertiesof variables, mentioned as the comma-separated pair consists of "IgnoreProperties" andone of this values.

false | Do not include solutions inconsistent v the nature of variables. |

true | Include solutions inconsistent with the properties of variables. |

See Ignore assumptions on Variables.

### MaxDegree — Maximum degree of polynomial equations for which solver offers explicit formulas2 (default) | optimistic integer smaller sized than 5

Maximum level of polynomial equations because that which solver usesexplicit formulas, mentioned as a confident integer smaller sized than 5.The solver does not usage explicit formulas the involve radicals whensolving polynomial equations of a level larger 보다 the specifiedvalue.

See resolve Polynomial Equations that High Degree.

### PrincipalValue — Flag for returning one systems false (default) | true

Flag for returning one solution, mentioned as the comma-separatedpair consisting of "PrincipalValue" and also one ofthese values.

false | Return every solutions. |

true | Return only one solution. If an equation or a mechanism of equationsdoes not have a solution, the solver returns an empty symbolic object. |

See Return One Solution.

## Output Arguments

collapse all

### S — remedies of equation symbolic array

Solutions of one equation, returned as a symbolic array. Thesize that a symbolic range corresponds come the number of the solutions.

### Y — remedies of device of equations structure

Solutions of a device of equations, reverted as a structure. The variety of fields in the structure correspond to the variety of independent variables in a system. If "ReturnConditions" is collection to true, the solve role returns two added fields the contain the parameters in the solution, and the problems under which the equipment is true.

### y1,...,yN — services of device of equations symbolic variables

Solutions that a system of equations, went back as symbolic variables.The number of output variables or symbolic arrays should be same tothe variety of independent variables in a system. If you explicitlyspecify live independence variables vars, climate thesolver supplies the same order come return the solutions. If you carry out notspecify vars, the toolbox sorts independent variablesalphabetically, and then assigns the remedies for these variablesto the calculation variables.

### parameters — Parameters in solution vector of created parameters

Parameters in a solution, went back as a vector the generatedparameters. This output debate is just returned if ReturnConditions is true.If a solitary output discussion is provided, parameters isreturned together a field of a structure. If lot of output disagreements areprovided, parameters is changed as the second-to-lastoutput argument. The generated parameters execute not appear in the MATLAB® workspace.They should be accessed making use of parameters.

**Example: **

### conditions — problems under which options are precious vector that symbolic expressions

Conditions under which solutions are valid, returned as a vectorof symbolic expressions. This output discussion is only returned if ReturnConditions is true.If a single output dispute is provided, conditions isreturned together a field of a structure. If multiple output arguments areprovided, problems is went back as the lastoutput argument.

**Example: **

## Tips

If solve cannot find a solution and ReturnConditions is true, resolve returns one empty systems with a warning. If no services exist, solve returns one empty equipment without a warning.

If the solution has parameters and also ReturnConditions is true, settle returnsthe parameters in the solution and also the conditions under i beg your pardon thesolutions space true. If ReturnConditions is false,the solve role either chooses values of theparameters and returns the equivalent results, or return parameterizedsolutions without choosing certain values. In the latter case, fix alsoissues a warning indicating the worths of parameters in the returnedsolutions.

If a parameter walk not show up in any type of condition, itmeans the parameter have the right to take any facility value.

The calculation of solve can containparameters native the entry equations in enhancement to parameters introducedby solve.

Parameters presented by settle donot appear in the MATLAB workspace. They have to be accessed usingthe output discussion that includes them. Alternatively, to use theparameters in the MATLAB workspace usage syms toinitialize the parameter. For example, if the parameter is k,use syms k.

The change names parameters and also conditions arenot allowed as inputs to solve.

When addressing a mechanism of equations, always assignthe result to calculation arguments. Output disagreements let you access thevalues of the options of a system.

MaxDegree only accepts positiveintegers smaller than 5 because, in general, there are no explicitexpressions because that the root of polynomials that degrees higher than 4.

## Algorithms

When you usage IgnoreAnalyticConstraints, thesolver uses these rule to the expressions on both sides of anequation.

log(*a*) + log(*b*)=log(*a*·*b*) forall values of *a* and *b*. In particular,the following equality is valid because that all values of *a*, *b*,and *c*:

(*a*·*b*)*c*=*a**c*·*b**c*.

See more: Read The Lyrics To Cardi B & Bruno Mars' “ Please Me Baby Lyrics

log(*a**b*)=*b*·log(*a*) forall values of *a* and also *b*. In particular,the complying with equality is valid because that all worths of *a*, *b*,and *c*:

(*a**b*)*c*=*a**b*·*c*.

If *f* and *g* arestandard mathematics functions and also *f*(*g*(*x*))=*x* forall tiny positive numbers, *f*(*g*(*x*))=*x* isassumed to be valid because that all complex values *x*. Inparticular: