Skip to content Skip to navigation

Connexions

You are here: Home » Content » Programming in LabVIEW MathScript-An Engineering Cost Analysis Example Using If Statements

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

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

      What is in a lens?

      Lens makers point to Connexions 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 Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the authors

Lenses

What is a lens?

Definition of a lens

Lenses

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

What is in a lens?

Lens makers point to Connexions 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 Connexions member, a community, or a respected organization.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • National Instruments

    This module is included in aLens by: National InstrumentsAs a part of collection:"Introduction to LabVIEW MathScript"

    Comments:

    "This course provides a brief introduction to LabVIEW MathScript, the textual math componenet of LabVIEW. The modules for this course include typical syntax and programming methods commonly used […]"

    Click the "National Instruments" link to see all content affiliated with them.

Also in these lenses

  • NI Signal Processing

    This module is included inLens: Digital Signal Processing with NI LabVIEW and the National Instruments Platform
    By: Sam ShearmanAs a part of collection:"Introduction to LabVIEW MathScript"

    Comments:

    "Tutorial / Introduction to LabVIEW MathScript, a text-based component of National Instruments LabVIEW that allows you to run your .m file scripts in LabVIEW Virtual Instruments."

    Click the "NI Signal Processing" link to see all content selected in this lens.

Recently Viewed

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

Programming in LabVIEW MathScript-An Engineering Cost Analysis Example Using If Statements

Module by: Anthony Antonacci, Darryl Morrell Based on: Programming in MATLAB-An Engineering Cost Analysis Example Using If Statements by Darryl Morrell

Summary: This is an example of using LabVIEW MathScript 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.

Unit cost of Part A
n CA
1-4 $16.00
5-24 $14.00
25-99 $12.70
100 or more $11.00
Unit cost of Part B
n CB
1-9 $24.64
10-49 $24.32
50-99 $24.07
100 or more $23.33
Unit cost of Part C
n CC
1-24 $17.98
25-49 $16.78
50 or more $15.78
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 1


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 LABVIEW MATHSCRIPT program that will compute the total unit cost Cunit for a given value of the variable n.

Solution 2

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 LABVIEW MATHSCRIPT program that will compute and plot the total unit cost as a function of n for values of n from 1 to 150.

Solution 3

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.
Solution3_If.bmp

Comments, questions, feedback, criticisms?

Send feedback