fsolve
solve one or more equations using floating-point arithmetic
Calling Sequence
Parameters
Basic Information
Description
Calling Sequence Shortcuts
Output
Units
Optional Arguments
Examples
References
Compatibility
fsolve(equations, variables, complex, fulldigits, useunits, interval, starting_values, options)
equations
-
equation, set(equation), list(equation), procedure, list(procedure)
variables
(optional) name or set(name); unknowns for which to solve
complex
(optional) literal name; search for complex solutions
fulldigits
(optional) literal name; use Digits setting for all computations
useunits
(optional) literal name; deal with units returned by procedures that aren't autodetected
interval
(optional) range, equation, set(equation), or list(range); specify a range in which to search for solutions
starting_values
(optional) equation, set(equation), or list(value); specify initial value used by solver. You cannot specify the variables option if you specify this option.
options
(optional) equation(s) of the form option=value where option is one of avoid, maxsols, useunits, method, digits, absftol, epsilon; specify solution options
This help page contains complete information about the fsolve command. For basic information on the fsolve command, see the fsolve help page.
The fsolve command numerically solves one or more equations for their unknowns.
In the equations parameter, if you specify an expression expr, Maple interprets it as the equation expr=0.
If you do not specify the variables parameter, Maple solves for all the variables that appear in equations, that is, indets(equations, name).
The solutions to a single equation are returned as an expression sequence.
The solutions to a set or list of equations are returned as sets of equation sequences.
The solutions to a list of procedures are returned as a sequence of values.
Note: If you specify a single equation and a set of variables, the solutions are returned as sets of equation sequences.
For a single polynomial equation of one variable, the fsolve command computes all real (non-complex) roots. It may not return all roots for exceptionally ill-conditioned polynomials.
To compute all roots of a polynomial over the field of complex numbers, use the complex option.
For a general equation or system of equations or procedures, the fsolve command computes a single real root.
If the fsolve command does not find any solutions, it returns the empty sequence (NULL) or returns unevaluated. This means that there are no solutions, or the fsolve command cannot find any solutions.
It is recommended that you specify an interval option. This may return a solution that was not initially found.
If the fsolve command returns no solution to a general equation or system of equations, you can search for a complex solution by specifying the complex option In addition, you can also specify a complex interval or complex starting_values option.
The fsolve command can deal with expressions and procedures that involve units in most situations. Unit handling is active in the following situations:
If equations is an equation or expression or collection of equations or expressions, then one can specify all of the following with units: an interval for one of the variables, an initial value, or a point to be avoided. If more than one of these values is specified for a single variable (as is always the case when specifying an interval: there are two bounds), then fsolve chooses one of the values to provide the unit that all other values for this variable are converted to. If a value cannot be converted to this unit, then the arguments are not specified properly and fsolve aborts with an error message.
In this case, the value(s) returned by fsolve for such a variable will have the proper unit attached.
The same functionality is available if equations is a procedure or collection of procedures.
If equations is an equation or expression or collection of equations or expressions, and a unit occurs inside it (as found by the hastype command), then the fsolve command will attempt to strip the unit off of the result before numerical evaluation.
If equations is a procedure or collection of procedures, then fsolve cannot detect if any units occur inside it. Instead, if any of the input values have units as described above, then each procedure is wrapped in another procedure that strips the unit off of the result before returning it. In some cases, the input arguments provided for the procedure(s) do not have units, but the output does; this situation cannot be detected automatically. In such a case, use the useunits option to force wrapping of the procedures.
avoid
avoid = set(equation) or set(set(equation)) or set(list(values)) or set(values)
For example, avoid = {x=0, x=1}, avoid = {{x=0, y=0}, {x=0, y=exp(1)}} or avoid = {[0, 1]}.
Avoid specified values when searching for roots. The left-hand side of each equation must be a variable name, unless equations is a list of procedures in which case only the right-hand side value must be provided. The right-hand side is the corresponding numeric value to avoid. To avoid values for a single variable, specify a set of equations. To avoid values for multiple variables, specify a set of sets of equations. To avoid values for a list of procedures, specify a set of lists of numeric values. To avoid values for a single procedure, specify a set of numeric values.
When using the avoid option, it is recommended that you specify a starting_values option to facilitate converging to a different solution.
Find one root (or all roots, for polynomials) over the complex floating-point numbers.
Prevent fsolve from decreasing Digits for intermediate calculations at high settings of Digits. With this option, fsolve may escape ill-conditioning problems, but is slower.
useunits option
useunits = list or set of variable/unit pairs
useunits = list of units
The fsolve command can automatically deal with equations and expressions that contain units in most situations, and procedures that contain units if the units are given in initial values or ranges, as explained in the Units section. This option can be used in three ways:
When used as just the keyword useunits, this option turns on code for dealing with units if those units had not been detected from the presence in other arguments. This is particularly useful if you specify procedures that return a value with units.
When used to specify a list or set of variable/unit pairs, such as x :: Unit(m), which is possible only if expressions or equations, rather than procedures, are submitted to fsolve, then this associates the given unit with the given variable. This is particularly useful if no initial value or range can be specified for the variable, or if the initial point is 0 (with which no unit can be associated in Maple).
When used to specify a list of units, such as Unit(m), which is possible only if procedures, rather than expressions or equations, are submitted to fsolve, then this associates the given units with the arguments to the procedure, in the order they are given. The number of units given must equal the number of arguments to the procedure.
interval option
range, equation, set(equation), or list(range)
For example, 1..2, x = 1..2, {x = 1..2, y = 10..20}, or [1..2, 10..20].
Search for roots only in the specified interval. The ranges are closed intervals. That is, the endpoints are included in the range. The left-hand side of each equation must be a variable name, unless equations is a list of procedures in which case only the right-hand side range values must be provided. The right-hand side is the corresponding interval to search. To specify a range for a single variable, specify an equation. To specify a range for multiple variables, specify a set of equations. To specify a range for a list of procedures, specify a list of ranges.
In conjunction with the complex option, you can specify a complex interval (rectangle in the complex plane) option using the syntax lower_left_point..upper_right_point, for example, x = -1 - I..1 + I.
maxsols
maxsols = posint
Find only the specified number of least roots. This option is valid only for a single univariate polynomial equation, in which case the fsolve command computes more than one root.
method
method = NAG, hefroots, ABND, RC, RS, PW, HR, subdivide, or NextZero
Use the specified method for the numeric root finding of an equation of one variable. The methods NAG, ABND, RC, RS, PW, HR, and hefroots pertain to a polynomial in one variable.
The default for a polynomial is to utilize RootFinding:-Isolate with none of its methods specified. The methods ABND, RC, RS, PW and HR are passed to RootFinding:-Isolate, if specified. Specifying either the PW or HR method allows non-real (complex) solutions to be returned, unless the option real is specified.
The NAG method utilizes a modified Laguerre algorithm, followed by iterated root polishing.
The methods subdivide and NextZero pertain to an equation in one variable that is not a polynomial. The method subdivide repeatedly subdivides the specified range amongst roots already found. The method NextZero uses the command RootFinding:-NextZero to repeatedly search past the last root found. The method subdivide may be more suitable for discontinuous expressions or those with non-isolated roots. When either method = subdivide or method = NextZero is specified, the maxsols option must also be provided.
starting_values option
equation or set(equation)
For example, x = 1.2, {x = 1.2, y = 10}, or [1.2, 10].
Specify starting values for the variables. You cannot specify the variables option if you specify this option. If the method that fsolve chooses for a particular problem requires more than one starting value, then the additional values are generated by perturbing the given starting values.
digits, absftol, and epsilon options
The digits keyword option takes a positive integer that specifies the maximal working precision (Digits) that will be set by fsolve. If not specified the value may be increased according to the algorithm.
The absftol keyword option takes a positive float that specifies an acceptance criterion for the norm of the forward error. If not specified the value will be set according to the algorithm.
The epsilon keyword option takes a positive float that specifies an acceptance criterion for the norm of the change in the variables for the current iteration step. If not specified the value will be set according to the algorithm.
A Polynomial equation in one variable
Finding solutions to univariate polynomials
By default, the fsolve command finds all real solutions to a univariate polynomial equation.
polynomial≔23⁢x5+105⁢x4−10⁢x2+17⁢x:
fsolve⁡polynomial
−4.536168981,−0.6371813185,0.
Using the maxsols option
To find only 2 real solutions, use the maxsols option.
fsolve⁡polynomial,x,maxsols=2
−4.536168981,−0.6371813185
Finding only real solutions in an interval
To find only real solutions in an interval, specify the interval.
fsolve⁡polynomial,x,−1..1
−0.6371813185,0.
Finding complex solutions
To find all the complex solutions, specify the complex option.
fsolve⁡polynomial,x,complex
−4.536168981,−0.6371813185,0.,0.3040664543−0.4040619058⁢I,0.3040664543+0.4040619058⁢I
General Equations and Systems of Equations
Finding solutions to a general solution or system of equations
By default, the fsolve command finds one real solution to a general equation or system of equations.
fsolve⁡tan⁡sin⁡x=1
0.9033391108
Specifying the interval for a solution
You can specify the interval in which to search for a solution.
f≔sin⁡x+y−exp⁡x⁢y=0:
g≔x2−y=2:
fsolve⁡f,g,x=−1..1,y=−2..0
x=−0.6687012050,y=−1.552838698
Specifying a list of procedures as input
You can also specify a list of procedures as input.
f := proc(x,y) sin(x + y) - exp(x)*y end proc:
g := proc(x,y) x^2 - y - 2 end proc:
fsolve⁡f,g,−1..1,−2..0
−0.66870120500236006,−1.5528386984284155
Using the complex option to find complex solutions
If an equation has no real solutions or you are interested in complex solutions, you can search for a complex solution using the complex option.
f≔ln⁡v=v2
fsolve⁡f
fsolve⁡ln⁡v=v2,v
fsolve⁡f,v,complex
0.6143632454−0.6810654878⁢I
Specifying a complex interval
To find a complex solution in a rectangle in the complex plane, specify a complex interval.
fsolve⁡f,v,v=−1−I..1+0.5⁢I,complex
fsolve⁡f,v,v=−1−0.5⁢I..1+I,complex
0.6143632454+0.6810654878⁢I
Examples with units
Consider the following model of a parabolic suspension cable. We specify the length of a cable and the sag, and we want to know what the span covered by that cable is. According to Karnovsky and Lebed (see References), we have
cable_length=int⁡sqrt⁡1+4⁢ratio2⁢2⁢xspan−12,x=0..spanassuming0<span,0<ratio
cable_length=span⁢4⁢16⁢ratio2+1⁢ratio+arcsinh⁡4⁢ratio8⁢ratio
where ratio=sagspan. Approximating for ratio near 0:
lhs⁡=series⁡rhs⁡,ratio,8
cable_length=span+83⁢span⁢ratio2−325⁢span⁢ratio4+2567⁢span⁢ratio6+O⁡ratio8
eval⁡convert⁡,polynom,ratio=sagspan
cable_length=span+8⁢sag23⁢span−32⁢sag45⁢span3+256⁢sag67⁢span5
cable_length≔100⁢Unit⁡ft
cable_length≔100⁢ft
sag≔2.738⁢Unit⁡ft
sag≔2.738⁢ft
fsolve⁡,span=10⁢Unit⁡ft..1000⁢Unit⁡ft
99.80004926⁢ft
We reformulate the same problem in terms of a procedure.
p≔unapply⁡rhs⁡−lhs⁡,span
p≔span↦span+19.99105067span⋅ft2−359.6778961span3⋅ft4+15407.86938span5⋅ft6−100⋅ft
fsolve⁡p,10⁢Unit⁡ft..1000⁢Unit⁡ft
A range can be specified with different units, but they have to be consistent - otherwise the fsolve command issues an error message.
fsolve⁡,span=10⁢Unit⁡ft..100⁢Unit⁡m
fsolve⁡,span=10⁢Unit⁡ft..1000⁢Unit⁡s
Error, (in fsolve) units problem, right range limit span = 1000*Units:-Unit(s) is not compatible with Units:-Unit(ft)
If we want the result in fathoms, we can associate that unit with the variable span, even if we do not supply a range.
fsolve⁡,span,useunits=span::Unit⁡fathom
16.63334154⁢fathom
Other Options
Using the avoid option to ignore solutions
To ignore solutions, use the avoid option.
fsolve⁡sin⁡x,x=−5..8,avoid=x=0,x=π,x=−π
6.283185307
fsolve⁡cos,−5..3,avoid=1.570796327,−1.570796327
−4.712388980
To find a solution near a value, specify a starting value.
fsolve⁡sin⁡x,x=3.1
3.141592654
Using the avoid option to find additional solutions
In the following example, fsolve(f, 1.0), 1.0 is the initial value for the solver. After finding a solution, to find additional solutions, use the avoid option in subsequent fsolve calls.
f≔x↦x−cos⁡x:
fsolve⁡f,1.0
0.7390851332
f,g≔1−x2−y2,x2+y2−1
f,g≔−x2−y2+1,x2+y2−1
S1≔fsolve⁡f,g,x=−1.0,y=0.1
S1≔x=−0.9949874371,y=0.1
S2≔fsolve⁡f,g,x=1.0,y=−0.1,avoid=S1
S2≔x=0.9949874371,y=−0.1
S3≔fsolve⁡f,g,x=0.1,y=0.5,avoid=S1,S2
S3≔x=0.1,y=0.9949874371
fsolve⁡f,g,x=−0.1,y=−0.5,avoid=S1,S2,S3
x=−0.1,y=−0.9949874371
Using the digits, absftol, and epsilon options to specify acceptance criteria
The following example does pass through zero, though its absolute forward error can be made small. Without specifiying extra options no root will be accepted, and fsolve returns unevaluated.
f≔x↦x−π2⋅x+π+1.×10−14:
fsolve⁡f,−4..4
−3.141592654
By specifying the digits option approximate roots can be found that have small enough absolute forward error.
f≔x↦x−π2⋅x+π2+1.×10−14:
fsolve⁡f,−4..4,digits=20
−3.141592638
fsolve⁡f,−4..4,digits=20,maxsols=2
−3.141593167,−3.141592695
fsolve⁡sin⁡x,x=0..∞,method=subdivide,maxsols=5
3.141592654,6.283185307,9.424777961,12.56637061,18.84955592
I.A. Karnovsky and O. Lebed, Advanced Methods of Structural Analysis, Springer, 2010.
The method option was introduced in Maple 2023.
For more information on Maple 2023 changes, see Updates in Maple 2023.
The fsolve command was updated in Maple 2024.
The digits, absftol and epsilon options were introduced in Maple 2024.
The method option was updated in Maple 2024.
For more information on Maple 2024 changes, see Updates in Maple 2024.
See Also
Digits
dsolve/numeric
isolve
msolve
Numeric Computation in Maple
pdsolve/numeric
RootFinding:-Analytic
RootFinding:-Isolate
rsolve
solve
Download Help Document