
Symbolic Equations in Matlab
When it comes to solving symbolic equations in Matlab, there's a certain procedure you have to follow.
Let me give you an example.
Consider this second degree equation with one unknown.
$$ x^2 + 3x = 4 $$
What we need to do first is move all the terms to the left-hand side of the equation, so we get:
$$ x^2 + 3x - 4 = 0 $$
Then, we define the unknown variable as a symbolic variable using the syms function. It goes like this:
>> syms x
Now, we define the symbolic equation and assign it to a variable, let's say eqz.
>> eqz = x^2+3*x-4
At this point, we can use the solve() function to find the solutions of the equation, like this:
>> solve(eqz)
The solve() function will find the solutions (roots) of the equation x2+3x-4=0
ans=
-4
1
As you can see, in this case, the solutions of the equation are x1=-4 and x2=1.
Note. You can also use the solve() function to solve an equation with two or more unknowns.
Let me give you another example.
Consider this second degree equation with two unknown variables.
$$ x^2 - y^2 = 0 $$
In this case, we need to define two symbolic variables.
>> syms x y
The following procedure is the same as before.
We define the equation in symbolic form and assign it to the variable eqz2.
>> eqz2 = x^2-y^2
Finally, we solve the equation using the solve() function.
>> solve(eqz2)
In this case, the solution of the equation is
ans =
y
-y
This means that the solution has infinite solutions of the form x=y and x=-y.
This is how you can solve an equation of any degree with Matlab.