eq

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).

Syntax

A == B
eq(A,B)

Description

A == B creates a symbolic equation.

eq(A,B) is equivalent to A == B.

Input Arguments

A

Number (integer, rational, floating-point, complex, or symbolic), symbolic variable or expression, or array of numbers, symbolic variables or expressions.

B

Number (integer, rational, floating-point, complex, or symbolic), symbolic variable or expression, or array of numbers, symbolic variables or expressions.

Examples

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

More About

expand all

Tips

  • If A and B are both numbers, then A == B compares A and B and returns logical 1 (true) or logical 0 (false). Otherwise, A == B returns a symbolic equation. You can use that equation as an argument for such functions as solve, assume, ezplot, and subs.

  • If both A and B are arrays, then these arrays must have the same dimensions. A == B returns an array of equations A(i,j,...)==B(i,j,...)

  • If one input is scalar and the other an array, then == expands the scalar into an array of the same dimensions as the input array. In other words, if A is a variable (for example, x), and B is an m-by-n matrix, then A is expanded into m-by-n matrix of elements, each set to x.

See Also

| | | | | | |

Was this topic helpful?