Decompose a math function

Report a typo

Say there is a math function that you want to use in your program:

f(x)={x2+1if   x01/x2if   0<x<1x21if   x1f(x) = \left\{ \begin{array}{ll} x^2+1 & \text{if } \text{ } \text{ } x \leq 0 \\ 1/x^2 & \text{if } \text{ } \text{ } 0 < x < 1 \\ x^2-1 & \text{if } \text{ } \text{ } x \ge 1 \end{array} \right.

The template for this function is defined below. Let's decompose it!

Your task is to create three additional functions f1 -> if x ≤ 0 , f2 -> if 0 < x < 1, and f3 -> if x >= 1 for each case and complete the function f. Each function should accept x as an argument of the Double type and return a Double value.

Don't create the main() function and don't print anything, just complete the functions.

Examples:

f(0.5) returns 4.0

f(-4) returns 17.0

Write a program in Kotlin
fun f(x: Double): Double {
// call your implemented functions here
}

// implement your functions here
fun f1...

fun f2...

fun f3...
___

Create a free account to access the full topic