in
Numeric type of symbolic input
Syntax
Description
Examples
Express Condition on Symbolic Variable or Expression
The syntax in(x,type)
expresses the condition
that x
is of the specified type
. Express the
condition that x
is of type Real
.
syms x cond = in(x,'real')
cond = in(x, 'real')
Evaluate the condition using isAlways
. Because
isAlways
cannot determine the condition, it issues a warning and
returns logical 0
(false
).
isAlways(cond)
Warning: Unable to prove 'in(x, 'real')'. ans = logical 0
Assume the condition cond
is true using assume
,
and evaluate the condition again. The isAlways
function returns logical
1
(true
) indicating that the condition is
true.
assume(cond) isAlways(cond)
ans = logical 1
To use x
in further computations, clear its assumption recreating it
using syms
.
syms x
Express Conditions in Output
Functions such as solve
use
in
in output to express conditions.
Solve the equation sin(x) == 0
using solve
. Set
the option ReturnConditions
to true
to return
conditions on the solution. The solve
function uses
in
to express the conditions.
syms x [solx, params, conds] = solve(sin(x) == 0,'ReturnConditions',true)
solx = pi*k params = k conds = in(k, 'integer')
The solution is pi*k
with parameter k
under the
condition in(k,'integer')
. You can use this condition to set an
assumption for further computations. Under the assumption, solve
returns only integer values of k
.
assume(conds) k = solve(solx > 0, solx < 5*pi, params)
k = 1 2 3 4
To find the solutions corresponding to these values of k
,
use subs
to substitute
for k
in solx
.
subs(solx,k)
ans = pi 2*pi 3*pi 4*pi
Clear the assumption on k
to use it in further computations.
assume(params, 'clear')
Test if Elements of Symbolic Matrix Are Rational
Create symbolic matrix M
.
syms x y z M = sym([1.22 i x; sin(y) 3*x 0; Inf sqrt(3) sym(22/7)])
M = [ 61/50, 1i, x] [ sin(y), 3*x, 0] [ Inf, 3^(1/2), 22/7]
Use isAlways
to test if the elements of M
are
rational numbers. The in
function acts on M
element-by-element. Note that isAlways
returns logical
0
(false
) for statements that cannot be decided and
issues a warning for those statements.
in(M,'rational')
ans = [ in(61/50, 'rational'), in(1i, 'rational'), in(x, 'rational')] [ in(sin(y), 'rational'), in(3*x, 'rational'), in(0, 'rational')] [ in(Inf, 'rational'), in(3^(1/2), 'rational'), in(22/7, 'rational')]
isAlways(in(M,'rational'))
Warning: Unable to prove 'in(sin(y), 'rational')'. Warning: Unable to prove 'in(3*x, 'rational')'. Warning: Unable to prove 'in(x, 'rational')'. ans = 3×3 logical array 1 0 0 0 0 1 0 0 1
Input Arguments
Version History
Introduced in R2014b