# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# eq

Define equation

In previous releases, eq in some cases evaluated equations involving only symbolic numbers and returned logical 1 or 0. To obtain the same results as in previous releases, wrap equations in isAlways. For example, use isAlways(A == B).

## Syntax

A == Beq(A,B)

## Description

A == B creates a symbolic equation. You can use that equation as an argument for such functions as solve, assume, ezplot, and subs.

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

### Define and Solve Equation

Solve this trigonometric equation. Define the equation by using the relational operator ==.

syms x solve(sin(x) == cos(x), x)
ans = pi/4

### Plot Symbolic Equation

Plot the equation . Define the equation by using the == operator.

syms x y fimplicit(sin(x^2) == sin(y^2)) 

### Test Equality of Symbolic Expressions

Test the equality of two symbolic expressions by using isAlways.

syms x isAlways(x + 1 == x + 1)
ans = logical 1
isAlways(sin(x)/cos(x) == tan(x))
ans = logical 1

### Test Equality of Symbolic Matrices

Check the equality of two symbolic matrices.

A = sym(hilb(3)); B = sym([1, 1/2, 5; 1/2, 2, 1/4; 1/3, 1/8, 1/5]); isAlways(A == B)
ans = 3×3 logical array 1 1 0 1 0 1 1 0 1

If you 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); isAlways(A == B)
ans = 3×3 logical array 0 1 0 1 0 0 0 0 0

collapse all

### Tips

• Calling == or eq for non-symbolic A and B invokes the MATLAB® eq function. This function returns a logical array with elements set to logical 1 (true) where A and B are equal; otherwise, it returns logical 0 (false).

• 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 is 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.