MATLAB - Algebra



Prev TutorialNext Tutorial

So far, we have seen that all the examples work in MATLAB as well as its GNU, alternatively called Octave. But for solving basic algebraic equations, both MATLAB and Octave are little different, so we will try to cover MATLAB and Octave in separate sections.
We will also discuss factorizing and simplification of algebraic expressions.

Solving Basic Algebraic Equations in MATLAB

The solve function is used for solving algebraic equations. In its simplest form, the solve function takes the equation enclosed in quotes as an argument.
For example, let us solve for x in the equation x-5 = 0
solve('x-5=0')
MATLAB will execute the above statement and return the following result −
ans =
 5
You can also call the solve function as −

y = solve('x-5 = 0')
MATLAB will execute the above statement and return the following result −
y =
 5
You may even not include the right hand side of the equation −

solve('x-5')
MATLAB will execute the above statement and return the following result −
ans =
 5
If the equation involves multiple symbols, then MATLAB by default assumes that you are solving for x, however, the solve function has another form −
solve(equation, variable)
where, you can also mention the variable.
For example, let us solve the equation v – u – 3t2 = 0, for v. In this case, we should write −
solve('v-u-3*t^2=0', 'v')
MATLAB will execute the above statement and return the following result −
ans =
 3*t^2 + u

Prev TutorialNext Tutorial