Skip to content Skip to navigation Skip to collection information

Connexions

You are here: Home » Content » Freshman Engineering Problem Solving with MATLAB » Programming with M-Files: An Engineering Cost Analysis Example Using If Statements

Navigation

Recently Viewed

This feature requires Javascript to be enabled.
 

Programming with M-Files: An Engineering Cost Analysis Example Using If Statements

Module by: Darryl Morrell. E-mail the author

Summary: This is an example of using M-Files to solve a simple engineering cost analysis problem in which the cost to assemble a product depends on the cost of its components; the cost of components depends on the number of units to be assembled.

An Engineering Cost Analysis Example

Suppose you are a design engineer for a company that manufactures consumer electronic devices and you are estimating the cost of producing a new product. The product has four components that are purchased from electronic parts suppliers and assembled in your factory. You have received cost information from your suppliers for each of the parts; as is typical in the electronics industry, the cost of a part depends on the number of parts you order from the supplier.

Your assembly cost for each unit include the cost of labor and your assembly plant. You have estimated that these costs are C0=$45.00/unit.

The cost of each part depends on the number of parts purchased; we will use the variable n to represent the number of parts, and the variables CA, CB, CC, and CD to represent the unit cost of each type of part. These cost are given in the following tables.

Table 1: Unit cost of Part A
n CA
1-4 $16.00
5-24 $14.00
25-99 $12.70
100 or more $11.00
Table 2: Unit cost of Part B
n CB
1-9 $24.64
10-49 $24.32
50-99 $24.07
100 or more $23.33
Table 3: Unit cost of Part C
n CC
1-24 $17.98
25-49 $16.78
50 or more $15.78
Table 4: Unit cost of Part D
n CD
1-9 $12.50
10-99 $10.42
100 or more $9.62
The unit cost is Cunit = C0 + CA + CB + CC + CD. To find the unit cost to build one unit, we look in the above tables with a value of n=1; the unit cost is
$45.00+$16.00+$24.64+$17.98+$12.50 = $116.12
To find the unit cost to build 20 units, we look in the above tables with a value of n=20 and get
$45.00+$14.00+$24.32+$17.98+$10.42 = $109.72
As expected, the unit cost for 20 units is lower than the unit cost for one unit.

Exercise 1

Create an if statement that will assign the proper cost to the variable CA based on the value of the variable n.

Solution

if n >= 1 && n <= 4
    CA = 16.00;
elseif n >= 5 && n <= 24
    CA = 14.00;
elseif n >= 25 && n <= 99
    CA = 12.70;
else
    CA = 11.00;
end

Exercise 2

Create a script that will compute the total unit cost Cunit for a given value of the variable n.

Solution

This code by BrieAnne Davis:

if n>=1 && n<=4; %if n=1 to 4, CA is $16.00
    CA=16.00;
elseif n>=5 && n<=24; %if n=5 to 24, CA is $14.00
    CA=14.00;
elseif n>=25 && n<=99; %if n=25 to 99, CA is $12.70
    CA=12.70;
elseif n>=100; %if n=100 or more, CA is $11.00
    CA=11.00;
end %this ends the if statement for CA

if n>=1 && n<=9; %if n=1 to 9, CB is $24.64
    CB=24.64;
elseif n>=10 && n<=49; %if n=10 to 49, CB is $24.32
    CB=24.32;
elseif n>=50 && n<=99; %if n=50 to 99, CB is $24.07
    CB=24.07;
elseif n>=100; %if n=100 or more, CB is $23.33
    CB=23.33;
end %this ends the if statement for CB

if n>=1 && n<=24; %if n=1 to 24, CC is $17.98
    CC=17.98;
elseif n>=25 && n<=49; %if n=25 to 49, CC is $16.78
    CC=16.78;
elseif n>=50; %if n=50 or more, CC is $15.78
    CC=15.78;
end %this ends the if statement for CC

if n>=1 && n<=9; %if n=1 to 9, CD is $12.50
    CD=12.50;
elseif n>=10 && n<=99; %if n=10 to 99, CD is $10.42
    CD=10.42;
elseif n>=100; %if n=100 or more, CD is $9.62
    CD=9.62;
end %this ends the if statement
CO=45.00;
Cunit=CO + CA + CB + CC + CD;

Exercise 3

Create a m-file script that will compute and plot the total unit cost as a function of n for values of n from 1 to 150.

Solution

This code was originally written by Bryson Hinton and then modified:

cunit = zeros(1,150);
c0 = 45;
for n=1:150
    %compute price for part A
    if n >= 1  && n <= 4
        ca=16;
    elseif n >= 5  && n <= 24
        ca=14;
    elseif n >= 25  && n <= 99
        ca=12.7;
    else
        ca=11;
    end

    %compute price for part B
    if n >= 1 && n <= 9
        cb=24.64;
    elseif n >= 10 && n <= 49
        cb=24.32;
    elseif n >= 50 && n <= 99
        cb=24.07;
    else
        cb=23.33;
    end

    %compute price for part C    
    if n >= 1 && n <= 24
        cc=17.98;
    elseif n >= 25 && n <= 49
        cc=16.78;
    else
        cc=15.78;
    end

    %compute price for part D
    if n >= 1 && n <= 9
        cd=12.50;
    elseif n >= 10 && n <= 99
        cd=10.42;
    else
        cd=9.62;
    end

    %sum cost for all parts
    cunit(n)= c0+ca+cb+cc+cd;
end

% Plot cost as a function of n
plot(1:150,cunit);
xlabel('n (units)');
ylabel('cost (dollars)');
title('Cost/unit as a function of number of units');
This code produces the plot in Figure 1.
Figure 1: Cost as a function of number of units produced.
Figure 1 (costfig.png)

Exercise 4

Suppose that you decide to fire your workers, close down your plant, and have the assembly done offshore; in this arrangement, C0 = Cx + Cs, where Cx is the cost of offshore assembly and Cs is the cost of shipping assembled units from the assembler to your warehouse. After some investigation, you find an offshore assembler that gives you the following assembly costs as a function of the number of units to assemble:

Table 5: Unit cost of Assembly
n Cx
1-29 $40.00
30-59 $30.00
60 or more $22.00
You also find a shipping company that will ship the units from the assembler to your warehouse and whose freight charges are the following function of the number of units shipped :
Table 6: Unit cost of Shipping
n Cs
1-9 $20.00
10-24 $18.00
25-74 $16.00
75 or more $15.00
Update the m-file script in Exercise 3 to account for the changes in cost due to offshoring.

Collection Navigation

Content actions

Download:

Collection as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add:

Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks