Documentation |
Define equation
Note: In previous releases, eq evaluated equations and returned logical 1 or 0. Now it returns unevaluated equations letting you create equations that you can pass to solve, assume, and other functions. To obtain the same results as in previous releases, wrap equations in logical or isAlways. For example, use logical(A == B). |
A == B
eq(A,B)
Solve this trigonometric equation. To define the equation, use the relational operator ==.
syms x solve(sin(x) == cos(x), x)
ans = pi/4
Plot this trigonometric equation. To define the equation, use the relational operator ==.
syms x y ezplot(sin(x^2) == sin(y^2))
Check the equality of two symbolic matrices. Because the elements of both matrices are numbers, == returns logical 1s and 0s:
A = sym(hilb(3)); B = sym([1, 1/2, 5; 1/2, 2, 1/4; 1/3, 1/8, 1/5]); A == B
ans = 1 1 0 1 0 1 1 0 1
If you use == to compare a matrix and a scalar, then == expands the scalar into a matrix of the same dimensions as the input matrix:
A = sym(hilb(3)); B = sym(1/2); A == B
ans = 0 1 0 1 0 0 0 0 0
If the input arguments are symbolic variables or expression, == does not return logical 1s and 0s. Instead, it creates equations:
syms x x + 1 == x + 1 sin(x)/cos(x) == tan(x)
ans = x + 1 == x + 1 ans = sin(x)/cos(x) == tan(x)
To test the equality of two symbolic expressions, use logical or isAlways. Use logical when expressions on both sides of the equation do not require simplification or transformation:
logical(x + 1 == x + 1)
ans = 1
Use isAlways when expressions need to be simplified or transformed or when you use assumptions on variables:
isAlways(sin(x)/cos(x) == tan(x))
ans = 1