By the end of this chapter, you will be able to:
Mastering these skills will help you solve real-world problems and make smart decisions in computer science and technology fields.
Calculus forms a foundational pillar in computer science, providing tools to model and analyze changing systems, optimize algorithms, and understand computational complexity. In Kenyan software development, data science, and artificial intelligence sectors, calculus enables precise computation of rates of change and accumulation, critical in machine learning and network traffic management. This chapter begins with the essential concept of functions, which are fundamental in programming and algorithm design, before progressing into their types and evaluation.
Functions describe relationships between inputs and outputs, vital for algorithms and data transformations in computer science. Understanding domain and range helps define valid inputs and expected outputs, while linear and power functions model various computational phenomena. Evaluating functions precisely is crucial for implementing correct software logic and simulations.
A function is a rule that assigns each element from a set of inputs (domain) to exactly one element in a set of outputs (range). Formally, a function \( f \) from a set \( A \) (domain) to a set \( B \) (range) is denoted as \( f: A \to B \), where for every \( x \in A \), there exists a unique \( y \in B \) such that \( y = f(x) \).
$$ f: A \to B \quad \text{where} \quad y = f(x) $$
Example 1: In a Kenyan e-commerce application, define a function \( f \) that maps the number of items \( x \) a customer buys to the total price \( y \) in Ksh, where each item costs 500 Ksh. Write the function and find \( y \) when \( x = 3 \).
Given:
Cost per item = 500 Ksh
Number of items \( x = 3 \)
$$ f(x) = 500x $$$$ f(3) = 500 \times 3 $$$$ f(3) = 1500 $$
Answer: 1500 Ksh
Example 2: Let \( f(x) = 2x + 5 \) represent the time in minutes to process \( x \) data packets in a network server. Find the output when \( x = 10 \).
Given:
\( f(x) = 2x + 5 \)
\( x = 10 \)
$$ f(10) = 2 \times 10 + 5 $$$$ f(10) = 20 + 5 $$$$ f(10) = 25 $$
Answer: 25 minutes
Example 3: A function \( f \) maps the number of users \( x \) on a website to the server load \( y \) given by \( f(x) = \frac{x}{x+1} \). Calculate \( f(4) \).
Given:
\( f(x) = \frac{x}{x+1} \)
\( x = 4 \)
$$ f(4) = \frac{4}{4+1} $$$$ f(4) = \frac{4}{5} $$$$ f(4) = 0.8 $$
Answer: 0.8 (server load ratio)
Example 4: In a Safaricom mobile billing system, the function \( f(x) = 20x + 100 \) gives the total monthly bill (in Ksh) for \( x \) GB of data used, with a base fee of 100 Ksh and 20 Ksh per GB. Find the bill for \( x = 5 \).
Given:
Base fee = 100 Ksh
Rate per GB = 20 Ksh
\( x = 5 \)
$$ f(5) = 20 \times 5 + 100 $$$$ f(5) = 100 + 100 $$$$ f(5) = 200 $$
Answer: 200 Ksh
The domain of a function is the set of all possible input values for which the function is defined. In computer science, specifying the domain prevents invalid inputs that may cause program errors or undefined behavior.
$$ \text{Domain} = \{ x \in \mathbb{R} \mid \text{function } f(x) \text{ is defined} \} $$
Example 1: Find the domain of \( f(x) = \frac{10}{x-3} \), representing a function calculating network latency depending on a parameter \( x \).
Given:
\( f(x) = \frac{10}{x-3} \)
The denominator cannot be zero:$$ x - 3 \neq 0 $$$$ x \neq 3 $$
Answer: Domain is all real numbers except \( x = 3 \), i.e., \( (-\infty, 3) \cup (3, \infty) \)
Example 2: Determine the domain of \( f(x) = \sqrt{x-2} \), used in image processing algorithms where \( x \) is pixel intensity.
Given:
\( f(x) = \sqrt{x-2} \)
For the square root to be real:$$ x - 2 \geq 0 $$$$ x \geq 2 $$
Answer: Domain is \( [2, \infty) \)
Example 3: Find the domain of \( f(x) = \log(x-1) \), representing logarithmic compression in audio signal processing.
Given:
\( f(x) = \log(x-1) \)
Logarithm is defined for positive arguments:$$ x - 1 > 0 $$$$ x > 1 $$
Answer: Domain is \( (1, \infty) \)
The range of a function is the set of all possible output values it can produce. Understanding range helps predict the behavior of algorithms and the limits of computed results.
$$ \text{Range} = \{ y \in \mathbb{R} \mid y = f(x), x \in \text{Domain} \} $$
Example 1: Find the range of \( f(x) = 2x + 3 \), a linear function modeling time complexity.
Given:
\( f(x) = 2x + 3 \)
Domain: all real numbers
Since \( f \) is linear with no restrictions, the range is all real numbers.
Answer: Range is \( (-\infty, \infty) \)
Example 2: Find the range of \( f(x) = \sqrt{x} \), representing computation time growing with input size.
Given:
\( f(x) = \sqrt{x} \)
Domain: \( [0, \infty) \)
Since square root outputs non-negative numbers:
Answer: Range is \( [0, \infty) \)
Example 3: Determine the range of \( f(x) = \frac{1}{x} \), used in algorithms where inverse proportionality applies.
Given:
\( f(x) = \frac{1}{x} \)
Domain: \( (-\infty, 0) \cup (0, \infty) \)
The function can take all real values except zero:
Answer: Range is \( (-\infty, 0) \cup (0, \infty) \)
Linear functions have the form \( f(x) = mx + c \), where \( m \) is the slope and \( c \) the intercept. They model proportional relationships common in computer science, such as runtime versus input size in simple algorithms.
$$ f(x) = mx + c $$
Example 1: A server’s processing time \( T \) in milliseconds depends linearly on the number of requests \( x \) as \( T = 5x + 20 \). Find \( T \) when \( x = 10 \).
Given:
\( T = 5x + 20 \)
\( x = 10 \)
$$ T = 5 \times 10 + 20 $$$$ T = 50 + 20 $$$$ T = 70 $$
Answer: 70 ms
Example 2: The monthly data cost \( C \) in Ksh is modeled as \( C = 1000x + 500 \), where \( x \) is data in GB. Calculate \( C \) for 15 GB.
Given:
\( C = 1000x + 500 \)
\( x = 15 \)
$$ C = 1000 \times 15 + 500 $$$$ C = 15000 + 500 $$$$ C = 15500 $$
Answer: 15,500 Ksh
Example 3: A computer program’s memory usage \( M \) in MB is \( M = -3x + 100 \), where \( x \) is the number of completed tasks. Find \( M \) for \( x=20 \).
Given:
\( M = -3x + 100 \)
\( x = 20 \)
$$ M = -3 \times 20 + 100 $$$$ M = -60 + 100 $$$$ M = 40 $$
Answer: 40 MB
Power functions have the form \( f(x) = ax^n \), where \( a \) and \( n \) are constants. They model polynomial time complexities and growth rates in computing.
$$ f(x) = ax^n $$
Example 1: The time \( T \) in seconds to process \( x \) data blocks is \( T = 2x^2 \). Find \( T \) for \( x=4 \).
Given:
\( T = 2x^2 \)
\( x = 4 \)
$$ T = 2 \times 4^2 $$$$ T = 2 \times 16 $$$$ T = 32 $$
Answer: 32 seconds
Example 2: The energy consumption \( E \) of a server is modeled as \( E = 5x^3 \), where \( x \) is the CPU load percentage. Find \( E \) for \( x=3 \).
Given:
\( E = 5x^3 \)
\( x = 3 \)
$$ E = 5 \times 3^3 $$$$ E = 5 \times 27 $$$$ E = 135 $$
Answer: 135 units
Example 3: The storage requirement \( S \) in GB for a dataset grows as \( S = 0.1x^{1.5} \), where \( x \) is the number of records in thousands. Compute \( S \) for \( x=8 \).
Given:
\( S = 0.1x^{1.5} \)
\( x = 8 \)
Calculate \( 8^{1.5} = 8^{1 + 0.5} = 8 \times \sqrt{8} = 8 \times 2.8284 = 22.627 \)
$$ S = 0.1 \times 22.627 $$$$ S = 2.2627 $$
Answer: 2.26 GB
Evaluating a function means computing the output for a given input, a fundamental operation in programming and algorithm implementation.
$$ y = f(x) $$
Example 1: Evaluate \( f(x) = 3x + 7 \) for \( x = 5 \) in a user authentication system.
Given:
\( f(x) = 3x + 7 \)
\( x = 5 \)
$$ f(5) = 3 \times 5 + 7 $$$$ f(5) = 15 + 7 $$$$ f(5) = 22 $$
Answer: 22
Example 2: Evaluate \( f(x) = x^2 - 4x + 6 \) for \( x = 3 \) in graphics rendering time model.
Given:
\( f(x) = x^2 - 4x + 6 \)
\( x = 3 \)
$$ f(3) = 3^2 - 4 \times 3 + 6 $$$$ f(3) = 9 - 12 + 6 $$$$ f(3) = 3 $$
Answer: 3
Example 3: Evaluate \( f(x) = \frac{2x + 1}{x - 2} \) for \( x = 4 \) in network throughput calculation.
Given:
\( f(x) = \frac{2x + 1}{x - 2} \)
\( x = 4 \)
$$ f(4) = \frac{2 \times 4 + 1}{4 - 2} $$$$ f(4) = \frac{8 + 1}{2} $$$$ f(4) = \frac{9}{2} $$$$ f(4) = 4.5 $$
Answer: 4.5
Create a free account to open more of this chapter.
Free: practical guides, quick cards, workplace scenarios and more.
Create a free accountThis chapter began by exploring functions, defining their nature and examining key concepts such as domain, range, linear functions, power functions, and how to evaluate them. It then moved on to graphing functions, focusing on identifying intercepts and understanding limits to describe behaviour near specific points. Differential calculus was introduced through the concept of rate of change, followed by the fundamental rules for finding derivatives and applying these to optimization problems. The study of first and second order differential equations provided methods to model and solve relationships involving rates of change. Integral calculus was covered next, distinguishing between definite and indefinite integrals and their applications. Finally, various techniques of integration were detailed, including integration by parts, the reverse chain rule, and u-substitution, equipping students with tools to handle complex integral problems. Throughout, the chapter combined theoretical foundations with practical calculation methods essential for computer science applications.
A function \(f(x) = 3x + 5\) models the response time (in milliseconds) of a server given \(x\) concurrent users. Calculate \(f(10)\). (2 marks)
Consider the power function \(g(x) = 2x^3\) representing the computational complexity of an algorithm. Find \(g(4)\). (2 marks)
At the start of this chapter we promised you would be able to:
Tick each one you can genuinely do.
So, are you there yet?
You're competent when you can confidently do 50% or more of what this chapter promised.
Sign in to record how you're doing.