SUNY Geneseo Department of Mathematics

Lab 5—Piecewise Function Definitions

Math 230 02
Spring 2016
Prof. Doug Baldwin

Complete by Monday, March 21
Grade by Wednesday, March 23

Purpose

This exercise begins developing your ability to program with “if” statements. It does so by asking you to write Matlab functions that evaluate some piecewise function definitions. The key points exercised by this lab are therefore (1) “if” statements, (2) piecewise definitions of mathematical functions, and (3) writing Matlab functions.

Background

Our textbook introduces “if” statements in chapter 12, particularly sections 12.1 and 12.2. We will discuss this material in class on March 7. We will also look at some examples of “if” statements applied to piecewise function definitions as part of that discussion.

The last problem below asks you to implement a “recursive” or “inductive” piecewise definition. We will talk about such definitions and their implementation in Matlab in class on March 9.

Activity

Write Matlab functions that compute each of the mathematical functions defined below.

Function 1

The following piecewise linear approximation to x2 between x = 0 and x = 1:

For one point of extra credit, identify a connection between this function definition and the Mean Value Theorem from calculus.

Function 2

When plotted, the following function looks like a hemispherical dent in an otherwise flat plane, so I call the function the “dent” function, d(x,y):

Function 3

The factorial function for non-negative integers can be recursively defined piecewise as follows:

Follow-Up

I will grade this exercise in a face-to-face meeting with you. During this meeting I will look at your solution, ask you any questions I have about it, answer questions you have, etc. Please bring your solution on your computer, as that will speed the process along.

Sign up for a meeting via Google calendar. Please make the meeting 15 minutes long, and schedule it to finish before the end of the “Grade By” date above.