Help › Functions
Solving
Find Minerr Maximize Minimize Odesolve root polyroots
Find(x, y, …) As in Mathcad
The values of the unknowns that satisfy the constraints in the solve block above it.
Give each unknown a guess value first. Then write Given, the constraints, and Find below them. Constraints use = (typed as a single equals sign), <, >, ≤, ≥. One unknown gives a number; several give a vector, which you can take apart: a vector of names (p; q) := Find(x, y) is written with a matrix of names on the left.
An unknown can be a number, a complex number, a vector or a matrix, and have units. The constraints use the same units.
To use a solve block as a function of a parameter, define f(a) := Find(x) with the constraints written in terms of a. After a Find that solves exactly, ERR is 0.
Units
The answer is in the guess's units, so a guess of 1·mA gives a current.
Refused
- No
Given above: a solve block must start with Given. - An unknown with no guess value above
Given. - "No solution was found": the constraints can't all be met. Try other guesses, or use
Minerr for the nearest answer. - A solve block with no constraints.
x≔1
y≔1
Given
x+y=5
x−y=1
Find(x,y)=(32)
Minerr(x, y, …) As in Mathcad
The values of the unknowns that come closest to meeting the constraints in the solve block above it.
Written as Find is, with guesses above Given. Where Find would fail because no answer meets every constraint, Minerr gives the least-squares nearest one, and does not report an error.
After Minerr, the variable ERR holds how far the answer is from meeting the constraints (inequalities count too). A small ERR means a good answer; check it before trusting the result.
Refused
- No
Given above. - An unknown with no guess value above
Given. - A solve block with no constraints.
q≔1
Given
q=1
q=2
Minerr(q)=1.5
ERR=0.707
Maximize(f, x, y, …) As in Mathcad
The values of the unknowns that make the function f as large as possible.
f is the name of a function defined above, and x, y, … are its arguments, each with a guess value above. If an unknown is a vector, f is called with the whole vector. It can be used alone, or after Given and constraints that the answer must meet.
It finds a local maximum near the guess; a different guess can find a different one. Use Minimize for the smallest value.
Refused
- A first argument that isn't a function.
- A function that rises without bound.
- Constraints that can't be met, from the guess given. Try another guess.
- A function that gives a complex number.
f(x)≔−(x−3)2+5
x≔1
Maximize(f,x)=3
Minimize(f, x, y, …) As in Mathcad
The values of the unknowns that make the function f as small as possible.
Used as Maximize is: f is the name of a function, the unknowns need guesses, and Given constraints can limit the answer. It finds a local minimum near the guess.
With a constraint x ≤ 2 after Given, a function whose lowest point is at 3 gives 2.
Refused
- A first argument that isn't a function.
- A function that falls without bound.
- Constraints that can't be met, from the guess given. Try another guess.
- A function that gives a complex number.
f(x)≔(x−3)2+1
x≔1
Minimize(f,x)=3
Odesolve([y,] t, b, [steps]) As in Mathcad
The solution of the differential equation in the solve block above it, as a function of t from the starting point to b.
Write Given, the equation, and its starting values, then define the answer: y := Odesolve(t, b). The equation uses the derivative operator or primes, as y''(t) + y(t) = 0, and needs one starting value for each order, as y(0) = 0 and y'(0) = 1. The result is a function: y(1)= reads it. It is only defined from the starting point to b.
For a system, give the unknowns as a vector first: Odesolve((x; y), t, b), with one equation for each. steps is the number of points the solution is calculated at, 1000 if omitted.
The conditions can also be given at two points, for a boundary-value problem, as y(0) = 0 and y(b) = 1; two points at most, and two conditions for a second-order equation.
Units
The starting point, b and the values can carry units, which the answer then has.
Refused
- No
Given above. - Too few or too many conditions for the order of the equation.
- A condition that isn't a single value, as
y(1) + y'(1) = 0. - A function used beyond the interval it was solved over.
- Conditions at two points that can't be met.
Given
y′(t)=−y(t)
y(0)=1
y≔Odesolve(t,2)
y(1)=0.368
root(f(x), x, [a, b]) As in Mathcad
A value of x that makes the expression f(x) equal to 0.
There are two forms. With a guess, root(f(x), x), x must have a value defined above, and the search runs from there. With a bracket, root(f(x), x, a, b), the search stays between a and b, and f must have opposite signs at the two ends, so a root lies between them.
root finds real roots of real expressions. It is not part of a solve block. For polynomials, polyroots gives all the roots at once.
Units
The answer is in the units of the guess, or of a and b.
Refused
- A guess form with no value for x above.
- "No root near the guess": try another guess, or give a and b.
- A bracket where f has the same sign at both ends.
- A complex value of f.
- Three arguments, or more than four.
x≔1
root(x2−2,x)=1.414
root(x2−4,x,0,5)=2
polyroots(v) As in Mathcad
All the roots of the polynomial whose coefficients are in v, constant term first.
The vector v = (a₀; a₁; …; aₙ) stands for a₀ + a₁·x + … + aₙ·xⁿ. The answer is a vector of n roots, which may be complex. Zero coefficients at the high end are ignored. Coefficients can be complex.
Refused
- A polynomial of degree 0: at least two coefficients are needed (a lone constant, or all zeros, has none to find).
- Coefficients that aren't numbers.
p≔⎝⎛−611⎠⎞
polyroots(p)=(−32)