How to calculate the domain and range of a function?

1

Good morning.

I have a web application in which based on a function I must present the domain and range of this function, for example, the function 2X + 3 obtain the domain and the range. I do not know if there is a library for this type of situations. I've searched math libraries like math.js but I can not find information about it. Thanks in advance.

    
asked by devjav 15.03.2018 в 00:47
source

1 answer

0

The numbers in javascript are limited to double precision floating numbers, defined in the standard IEEE 754 . It means that it does not support numbers less than -9007199254740991 or greater than 9007199254740991 . Therefore, it does not cover the domain of integers. If you do

console.log(9007199254740992 === 9007199254740993)

returns true , which is incorrect.

The accuracy of a double-precision floating point number reaches up to 16 digits, so it does not cover the domain of real numbers either. If you do

console.log(1.0000000000000001 === 1.000000000000000111)

Again returns true .

Finally, it also does not support complex or imaginary numbers:

Math.sqrt(-4)

Returns NaN .

There are online tools that can calculate domain and range, such as WolframAlpha:

link

But if you want to do it yourself, you would have to make a polynomial parser that would split the function definition into a syntax tree and evaluate, for example:

  • If there is a component with the form 1/(x -a) the domain excludes the real numbers where x is equal to a, and the range excludes the real numbers where y is equal to zero.
  • If there is a component with the form √(x-a) , the domain excludes the reals where X is less than A, and the range includes all real numbers greater than zero.
  • Functions such as sine and cosine have as their domain all real numbers, and as a range all reals between -1 and 1.
  • The exponential function has all reals as the domain, and as a range all reals greater than zero
  • The logarithm function has as domain all reals greater than zero and as a range all reals.

As long as the polynomial has several of these functions, its ranges and domains are defined by the intersection (not the union) of the ranges and domains of each component.

    
answered by 15.03.2018 в 14:00