Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this problem you will write a function to implement following math function:

ID: 3722338 • Letter: I

Question

In this problem you will write a function to implement following math function:

(This is an approximation of an activation function used in machine learning)

The function called "activation" should take an "input" of type double and should provide an "output" of type double. Let us assume that this function will be called by the following process() function, which is in-turn called by main(). (Hint there are two ways of getting the output from the function. You can use any option.

Note : This is for intro to C

2 2 2

Explanation / Answer


Based on the graph, the function is defined as

f(x) = -2 when x < -2
= 2 when x > 2
= x otherwise

Based on this function definition, the following code has been completed. The code prints the value at x = 1.5. You can change the value of dX to any other number (say -5 or 10) and check the output. Hope it helps.

#include <stdio.h>
//declare your function "activation" function here. [1 point]
double activation(double x);

//define your function "activation" function here. [10 points]
double activation(double dX)
{
if(dX < -2)
return -2;
else if(dX > 2)
return 2;
else
return dX;
}

void process(){
double dX;
double dFx;
//call your function "activation" function here. [4 points]
dX = 1.5;
dFx = activation(dX);
printf("f(%0.2lf)=%0.2lf ",dX,dFx);
}
int main(){
process();
return 0;
}

output

=====

f(1.50)=1.50

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote