Question

5.1  Plotting Functions Defined by Several Equations Example 4: Cell phone plans often have a flat rate...

5.1  Plotting Functions Defined by Several Equations

Example 4:

Cell phone plans often have a flat rate for a fixed amount of minutes and then a per minute charge for each minute over the fixed amount. Mathematically, this is described by a function with two different definitions depending on which part of the domain - if the value is less than the fixed amount or more.

For instance, if a company offers 500 minutes of calling for $25 and thereafter it is 25 cents per minute, a function that describes the amount you owe based on the number of minutes is

(Neglecting the onerous extra charges and taxes of course.)

To plot this function (Figure ), we handle each part of the function definition separately.

>> x1 = linspace(0,500);
>> y1 = 25 + 0*x1;              % note the funny 0*x1
>> x2 = linspace(500,1000);
>> y2 = 25+.25*(x2-500);        % if x>500 we use this line
>> plot(x1,y1,x2,y2),grid       % plot both    

Figure 3: Plot of phone charges

This example shows a funny trick to plot the horizontal line y2 = 25+0*x1 instead of simply y2 = 25. Try plotting both ways to see why we did so.

Exercise 9a:
Plot a graph that describes the following calling plan: You pay $35 for the first 1,000 minutes. After the first 1,000 minutes you pay $0.30 per minute. Draw a graph for usage between 0 and 2,000 minutes.

  1. What commands did you use?
For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac).

Homework Answers

Answer #1

MATLAB Code:

% MATLAB Script that plots the graph for the given calling plan

% Generating first 1000 minutes
x1 = linspace(0,1000);

% Generating from 1000 to 2000 minutes
x2 = linspace(1001, 2000);

% Equation 1
y1 = 35 + (0.*x1);

% Equation 2
y2 = 35 + (0.30 * (x2-1000));

% Plotting the graph
plot(x1,y1,x2,y2);
grid on;

__________________________________________________________________________________________

Sample Run:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT