CSE101Lec13.ppt - CSE101-Lec#13 \u2022 Math Library functions \u00a9LPU CSE101 C Programming Functions in Mathematics \u201cA relationship between two variables

CSE101Lec13.ppt - CSE101-Lec#13 u2022 Math Library...

This preview shows page 1 - 8 out of 23 pages.

©LPU CSE101 C Programming CSE101-Lec#13 Math Library functions
Image of page 1
©LPU CSE101 C Programming Functions in Mathematics “A relationship between two variables, typically x and y , is called a function , if there is a rule that assigns to each value of x one and only one value of y .” So, for example, if we have a function f ( x ) = x + 1 then we know that f (-2.5) = -2.5 + 1 = -1.5 f (-2) = -2 + 1 = -1 f (-1) = -1 + 1 = 0 f (0) = 0 + 1 = +1 f (+1) = +1 + 1 = +2 f (+2) = +2 + 1 = +3 f (+2.5) = +2.5 + 1 = +3.5
Image of page 2
©LPU CSE101 C Programming Functions in Mathematics Likewise, if we have a function a ( y ) = | y | then we know that a (-2.5) = | -2.5 | = +2.5 a (-2) = | -2 | = +2 a (-1) = | -1 | = +1 a (0) = | 0 | = 0 a (+1) = | +1 | = +1 a (+2) = | +2 | = +2 a (+2.5) = | +2.5 | = +2.5
Image of page 3
©LPU CSE101 C Programming Function Argument f ( x ) = x + 1 a ( y ) = | y | We refer to the thing inside the parentheses immediately after the name of the function as the argument (also known as the parameter ) of the function. In the examples above: the argument of the function named f is x ; the argument of the function named a is y .
Image of page 4
©LPU CSE101 C Programming Absolute Value Function in C The abs function calculates the absolute value of its argument. It’s the C analogue of the mathematical function a( y ) = | y | (the absolute value function) a= abs(y);
Image of page 5
©LPU CSE101 C Programming Absolute Value Function in C fabs(-2.5) returns 2.5 abs(-2) returns 2 abs(-1) returns 1 abs(0) returns 0 abs(1) returns 1 abs(2) returns 2 fabs(2.5) returns 2.5
Image of page 6
©LPU CSE101 C Programming Absolute Value Function in C #3 We say “ abs of -2 evaluates to 2” or “ abs of -2
Image of page 7
Image of page 8

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture