![]() |
VOOZH | about |
Algebra is all about the study of mathematical symbols and rules for manipulating these symbols. Here variables are used to store/represent quantities. In MATLAB, there are certain in-built methods to solve algebra equations. Roots of equations, solving for x, simplifying an expression are some things we can perform in MATLAB.
Following are some functions of MATLAB to solve algebra:
Solving Equations: To solve an equation for finding x value or if the equation contains multiple variables, we can solve for a particular variable.
Syntax: solve(equation,variable)
Here default variable will be x.
Example 1: This example illustrates the solve() function for the latest versions of MATLAB.
Output:
28
Example 2:
Output:
y = 28*z^2 + x
Finding Roots: Using roots() and solve() functions, one can find roots using an equation or coefficients of a variable in a particular equation. Let's see an example to get a better understanding
Syntax: roots(p) where p = column vector
Example 1:
Output:
ans = 28 ans = 4 3
Example 2:
Output:
a = 28 b = 3 4 c = 3 3 7
Factorization and Simplification: To find factors of an expression, factor() function is used. And to simplify an expression, simplify() function is used. When you work with many symbolic functions, you should declare that your variables are symbolic.
factor Syntax: factor(expression) or factor(integer) simplify Syntax: simplify(expression)
If an expression is passed into factor() function, then it returns an array of factors. If an integer is passed into factor() function, then it returns prime factorization of the given integer.
Example 1:
Output:
ans = 2 2 7 ans = (x - y)*(x^2 + x*y + y^2) ans = (x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 - x + 1)
Example 2: The simplify() function performs algebraic simplification of the given expression.
Output:
a = 1 b = x^2 + 4
Expand Function: Using the expand() function, we can expand given expressions and simplify inputs of functions using identities.
Syntax: expand(expression)
Example:
Output:
ans = x^2 - 6*x + 8 ans = cos(x)*cos(y) - sin(x)*sin(y) ans = 2*cos(x)*sin(x)
Note: