How to find all divisors of a number or expression in MatLab? - divisors -- MatLab
How to find all divisors of a number or expression in MatLab? - divisors -- MatLab
How to find all divisors of a number or expression in MatLab?
[Ans]
divisors
[description]
Find all divisors of a number or expression.
more details on:
code:
clear
clc
fprintf("divisors function.\n")
fprintf("divisor of 42.\n")
divisors(42)
fprintf("divisor of -42.\n")
divisors(-42)
fprintf("divisor of 1.\n")
divisors(1)
fprintf("divisor of -1.\n")
divisors(-1)
fprintf("divisor of 0.\n")
divisors(0)
fprintf("divisor of sym(42).\n")
divisors(sym(42))
syms x;
%equivalent
fprintf("divisor of (x^4-1).\n")
divisors(x^4 - 1, x)
fprintf("divisor of (x^4-1).\n")
divisors(x^4 - 1)
syms a u v
fprintf("divisor of a*u^2*v^3 where v are symbolic variables.\n")
divisors(a*u^2*v^3, v)
fprintf("divisor of a*u^2*v^3 where [u,v] are symbolic variables.\n")
divisors(a*u^2*v^3, [u,v])
fprintf("divisor of sym(9/8).\n")
divisors(sym(9/8))
result:
divisors function.
divisor of 42.
ans =
1 2 3 6 7 14 21 42
divisor of -42.
ans =
1 2 3 6 7 14 21 42
divisor of 1.
ans =
1
divisor of -1.
ans =
1
divisor of 0.
ans =
0
divisor of sym(42).
ans =
[1, 2, 3, 6, 7, 14, 21, 42]
divisor of (x^4-1).
ans =
[1, x - 1, x + 1, (x - 1)*(x + 1), x^2 + 1, (x^2 + 1)*(x - 1), (x^2 + 1)*(x + 1), (x^2 + 1)*(x - 1)*(x + 1)]
divisor of (x^4-1).
ans =
[1, x - 1, x + 1, (x - 1)*(x + 1), x^2 + 1, (x^2 + 1)*(x - 1), (x^2 + 1)*(x + 1), (x^2 + 1)*(x - 1)*(x + 1)]
divisor of a*u^2*v^3 where v are symbolic variables.
divisor of 42.
ans =
1 2 3 6 7 14 21 42
divisor of -42.
ans =
1 2 3 6 7 14 21 42
divisor of 1.
ans =
1
divisor of -1.
ans =
1
divisor of 0.
ans =
0
divisor of sym(42).
ans =
[1, 2, 3, 6, 7, 14, 21, 42]
divisor of (x^4-1).
ans =
[1, x - 1, x + 1, (x - 1)*(x + 1), x^2 + 1, (x^2 + 1)*(x - 1), (x^2 + 1)*(x + 1), (x^2 + 1)*(x - 1)*(x + 1)]
divisor of (x^4-1).
ans =
[1, x - 1, x + 1, (x - 1)*(x + 1), x^2 + 1, (x^2 + 1)*(x - 1), (x^2 + 1)*(x + 1), (x^2 + 1)*(x - 1)*(x + 1)]
divisor of a*u^2*v^3 where v are symbolic variables.
ans =
[1, v, v^2, v^3]
divisor of a*u^2*v^3 where [u,v] are symbolic variables.
ans =
[1, u, u^2, v, u*v, u^2*v, v^2, u*v^2, u^2*v^2, v^3, u*v^3, u^2*v^3]
divisor of sym(9/8).
ans =
[1, 3, 9, 1/2, 3/2, 9/2, 1/4, 3/4, 9/4, 1/8, 3/8, 9/8]
Comments
Post a Comment