In the Wolfram Language, Solve is a high level function with a wide range of uses.
You can use the Solve function for a single equation...
Or a system of equations...
And the equations do not have to be polynomials.
They can, for example, contain exponential terms...
Or even trigonometric terms...
Because the Solve function is so comprehensive and covers so many cases,
it would not be possible to give a complete overview in a single video.
So in this lesson,
we're going to focus on using the Solve function
to find the solutions to polynomial equations with 1 variable.
To solve a basic, linear equation using the Solve function,
you type in the equation with a double equal sign,
and then specify which variable to solve for.
The result is a list of solutions,
and each solution is itself a list of Rules ready for your next computation.
For basic equations,
it may not be clear why this is the best way to return the answer.
But as the number of solutions and number of variables grow,
the usefulness of this form will become apparent.
Solve can handle integers, rational numbers, real numbers, and complex numbers.
Your equation can have more than one variable.
This is why you need to specify the variable to solve for.
Changing the variable will change the solution.
There is no reason the variable has to be x.
Also, your equation may not have a solution.
In this case, Mathematica returns an empty list.
It's also possible that every number is a solution.
When this happens, Mathematica returns a list containing an empty list.
Here are the general rules for the form of the solutions.
For quadratic equations, you use the same approach.
You first enter the equation with a double equals...
then the variable to solve for.
The reason you use a double equal sign is because a single equal sign is used for assignment,
while the double equals is a logical comparison,
and the Solve function is designed to find all numbers that make the equation true.
The Wolfram Language has built in support for complex numbers.
If you solve a quadratic equation with a double root,
it returns the same solution twice.
Multiplicities are respected...
Solving a general quadratic equation for x gives us the quadratic formula.
Instead of a "plus or minus" sign, Mathematica gives you both solutions separately.
As we move beyond linear and quadratic equations,
we'll encounter results that may be unfamiliar to you.
For example,
if you solve a general cubic equation for x,
you get the solutions from the lesser known cubic formula.
To make this easier to read,
we'll display the 3 solutions using traditional math notation.
This formula has been around for hundreds of years,
but due to its complexity, students rarely memorize it.
Thankfully, with Mathematica, you don't have to.
The Wolfram Language can also return the solutions to a general 4th degree polynomial
by using the quartic formula.
To make this easier to read,
we'll display it in traditional math form,
and zoom out
1..
2..
3..
4..
5..
6..
7..
8 times,
until the expressions are fully visible.
While you could simplify these expressions by introducing a discriminant,
that's not necessary.
Focus on the bigger picture,
and let Mathematica do the computation for you.
If you try to solve a general quintic equation in Mathematica,
you'll get something completely different.
Mathematica doesn't return a complicated algebraic expression as you might expect.
Instead, you get 5 solutions involving a Root function.
Why the change?
Well, mathematicians looked for a quintic formula for over 250 years,
but could never find one.
And then, in the early 1800s,
Abel and Ruffini called off the search by showing that no such formula exists!
In fact, for polynomials of degree 5 and higher,
there are no general formulas at all!
This result is more than a mathematical curiosity.
You need to understand this
so you'll know WHY it's impossible for Mathematica to always return radical solutions
to polynomials of degree 5 or more.
Note -
there are special cases of polynomials of degree 5 and up
where the solutions CAN be computed.
In those cases, Mathematica will be able to provide the solutions...
Now that we know that Mathematica can always solve linear, quadratic, cubic, and quartic polynomials,
let's see some examples.
We'll first solve x^3 + 2x - 1 == 0.
The result displays the 3 solutions as Root objects.
Root expressions represent the exact solution,
but inside the rectangle, next to the radical icon, it displays an approximation for convenience.
If you want to see more digits for a Root object, you can use the N function.
The first argument is the number,
while the second is the number of digits you'd like.
You can combine these computations into a single line
by passing the Solve output into the N function.
To save typing, the Wolfram Language has an NSolve function that does this exact thing.
I'd like to pause a moment and answer the question I know you're puzzling over:
If Mathematica knows about the cubic formula,
then why didn't it return the exact solutions?
Why return Root objects?
You can request that the cubic formula be used by setting the Cubics option to True.
The solution in radicals is quite messy,
which is a good reason to return the Root objects.
For another example, let's solve a quartic equation.
Just like with the cubic,
the solutions are returned as Root objects
rather than busy-busy radical expressions.
If you want to see the full expression, just set the Quartics option to True.
As a final example, let's solve a 6th degree polynomial.
Because the degree is 6, we get a list with 6 solutions.
You can use each of the Root objects as a number,
and that's because they ARE numbers!
For example,
if you multiply the 6 roots together,
you get this expression.
And if you tell Mathematica to simplify this expression,
it does.
The product of all 6 roots is exactly -23...
Trust me...