How to set a range in symbolic variable in MatLab? - assume -- MatLab

 How to set a range in symbolic variable in MatLab? - assume -- MatLab


 How to set a range in symbolic variable in MatLab?

[Ans]

assume command

 How to set a range in symbolic variable in addition in MatLab?

[Ans]

assumeAlso command

 How to look at current assumption of the given variable?

[Ans]

assumptions command



assumptions

[Description]

take a look at current assumptions of x.

[Syntax]

assumptions(x)


assumeAlso

[Description]

It is similar to assume function,
but it is additive.

[Syntax]

Same as assume function.

assume

[Description]

assume function can assume  a symbolic variable between specific range or type with given expression.

It uses some simple conceptions of set.
When I comprehend it, I uses some simple conceptions of set.

[Syntax]

(1)assume(<cond>)

(2)assume(<expre>,<set>)
(3)assume(<expre>,'clear')

(1)assume(<cond>)
the state <cond> will be set to be valid.

(2)assume(<expre>,<set>)
the state of expression <expre> will be set to belong to the set <set>.


(3)assume(<expre>,'clear')
the <expre> will be cleared. it will set to be none.

[NOTE]

Great Importance!!! Pay a lot of attention on it!!!

(1)assume function is not additive 
i.e. when you use assume function, previous assumption about the variable in expression <expre> will be cleared.

(2) For multiple <variable>, use []
[] means vector

(3)For multiple <set>, use {}
{} means set

more details on:

[code]

the following code show that how to assume a variable.
clear
clc
syms x
%x<0
assume(x<0)
isAlways(x<0)
fprintf("1\n");
%even
assume(x/2,'integer')
isAlways(x<0)
fprintf("2\n");
%even
assume(x/2,'integer')
isAlways(mod(x,2)==1)
fprintf("3\n");
%odd
assume((x+1)/2,'integer')
isAlways(mod(x,2)==1)
fprintf("4\n");
%odd
assume((x-1)/2,'integer')
isAlways(mod(x,2)==1)
fprintf("5\n");
%multiple of 3
assume((x-1)/3,'integer')
isAlways(mod(x,3)==2)
fprintf("6\n");
%multiple of 3
assume((x+1)/3,'integer')
isAlways(mod(x,3)==2)
fprintf("7\n");
%multiple of 3
assume((x+1)/3,'integer')
isAlways(mod(x,3)==1)
fprintf("8\n");
%multiple of 3
assume((x+1)/3,'integer')
isAlways(mod(x,2)==1)
fprintf("9\n");
%multiple of 3
assume((x+1)/3,'integer')
isAlways(mod(x,3)==2)
fprintf("10\n");
%x>5 and x<10
assume(x>5 & x<10)
isAlways(mod(x,3)==2)
fprintf("11\n");
%x>5 and x<10
assume(x>5 & x<10)
isAlways(mod(x,18)==2)
fprintf("12\n");
%x<5 or x>13
assume(x<5 | x>13)
isAlways(mod(x,3)==2)
fprintf("13\n");
%x is not equal to -1
assume(x~=-1)
isAlways(x~=1)
fprintf("14\n");
%-1 <= x <= 1
%it can be represented in logical way
%or
%simple math way.
assume(-1<=x | x<=1)
isAlways(mod(x,3)==2)
fprintf("15\n");
assume(-1<=x<=1)
isAlways(mod(x,3)==2)
fprintf("16\n");
%x is an integer
assume(x,'integer')
isAlways(mod(x,3)==2)
fprintf("17\n");
%x>2 and x <10 where x is an integer
assume(in(x,'integer') & x>2 & x<10)
isAlways(mod(x,3)==2)
fprintf("18\n");
%x>2 and x <10 where x is not an integer
assume(~in(x,'integer') & x>2 & x<10)
isAlways(mod(x,3)==2)
fprintf("19\n");
%x is positive integer (positive and integer => positive integer)
assume(x,{'positive','integer'})
isAlways(mod(x,3)==2)
fprintf("20\n");
%x is a rational number. (x==a/b where gcd(a,b)==1 and a, b is integer)
assume(x,'rational')
isAlways(mod(x,3)==2)
fprintf("21\n");
%take look at assumptions of x
assumptions(x)


[Code]

clear
clc
syms x y;
assume(x<0);
assume(y>0);
assumptions([x y])
fprintf("1\n");
assume([x y],'integer');
assumptions([x y])
fprintf("2\n");
assumptions()
fprintf("3\n");

Comments