1 |
|
2 |
|
3 | # Function rationalize
|
4 |
|
5 | Transform a rationalizable expression in a rational fraction.
|
6 | If rational fraction is one variable polynomial then converts
|
7 | the numerator and denominator in canonical form, with decreasing
|
8 | exponents, returning the coefficients of numerator.
|
9 |
|
10 |
|
11 | ## Syntax
|
12 |
|
13 | ```js
|
14 | rationalize(expr)
|
15 | rationalize(expr, detailed)
|
16 | rationalize(expr, scope)
|
17 | rationalize(expr, scope, detailed)
|
18 | ```
|
19 |
|
20 | ### Parameters
|
21 |
|
22 | Parameter | Type | Description
|
23 | --------- | ---- | -----------
|
24 | `expr` | Node | string | The expression to check if is a polynomial expression
|
25 | `optional` | Object | boolean | scope of expression or true for already evaluated rational expression at input
|
26 | `detailed` | Boolean | optional True if return an object, false if return expression node (default)
|
27 |
|
28 | ### Returns
|
29 |
|
30 | Type | Description
|
31 | ---- | -----------
|
32 | Object | Node | The rational polynomial of `expr` or na object {Object} {Expression Node} expression: node simplified expression {Expression Node} numerator: simplified numerator of expression {Expression Node | boolean} denominator: simplified denominator or false (if there is no denominator) {Array} variables: variable names {Array} coefficients: coefficients of numerator sorted by increased exponent {Expression Node} node simplified expression
|
33 |
|
34 |
|
35 | ## Examples
|
36 |
|
37 | ```js
|
38 | math.rationalize('sin(x)+y')
|
39 | // Error: There is an unsolved function call
|
40 | math.rationalize('2x/y - y/(x+1)')
|
41 | // (2*x^2-y^2+2*x)/(x*y+y)
|
42 | math.rationalize('(2x+1)^6')
|
43 | // 64*x^6+192*x^5+240*x^4+160*x^3+60*x^2+12*x+1
|
44 | math.rationalize('2x/( (2x-1) / (3x+2) ) - 5x/ ( (3x+4) / (2x^2-5) ) + 3')
|
45 | // -20*x^4+28*x^3+104*x^2+6*x-12)/(6*x^2+5*x-4)
|
46 | math.rationalize('x/(1-x)/(x-2)/(x-3)/(x-4) + 2x/ ( (1-2x)/(2-3x) )/ ((3-4x)/(4-5x) )') =
|
47 | // (-30*x^7+344*x^6-1506*x^5+3200*x^4-3472*x^3+1846*x^2-381*x)/
|
48 | // (-8*x^6+90*x^5-383*x^4+780*x^3-797*x^2+390*x-72)
|
49 |
|
50 | math.rationalize('x+x+x+y',{y:1}) // 3*x+1
|
51 | math.rationalize('x+x+x+y',{}) // 3*x+y
|
52 |
|
53 | const ret = math.rationalize('x+x+x+y',{},true)
|
54 | // ret.expression=3*x+y, ret.variables = ["x","y"]
|
55 | const ret = math.rationalize('-2+5x^2',{},true)
|
56 | // ret.expression=5*x^2-2, ret.variables = ["x"], ret.coefficients=[-2,0,5]
|
57 | ```
|
58 |
|
59 |
|
60 | ## See also
|
61 |
|
62 | [simplify](simplify.md)
|