freeCodeCamp/guide/english/mathematics/functions/domain-and-codomain/index.md

1.8 KiB

title
Domain and Codomain

Domain and Codomain

Domain

The domain of a function defines what input values are valid for that specific function. Any value picked outside of that domain is undefined for that function

Example:

Have a look at the function f(x) = 1/x. Here x can be any real number, except for 0 since we would have 1 divided by 0 and we all know that division by zero is not allowed.

Sometimes, we define a subdomain for a function to limit the application of the function to only the desired cases. For example let's say we take the same function as above f(x) = 1/x, but we are only interested in the decreasing part of the function. In that case we would define our subdomain as only the positive numbers, 0 not included since 0 is not part of the domain.

Codomain

Very similar to the domain, the codomain defines a range of valid results for a function. The codomain is in other words, the domain of all the images of a given function.

Example:

If we look at the function f(x) = 1/x , we can say that the codomain is the set of all the real numbers, except for 0 since there exists no input for this function that would output 0 as a result.

More Information: