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

Lenses

What is a lens?

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.

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.
  • NSF Partnership display tagshide tags

    This module is included inLens: NSF Partnership in Signal Processing
    By: Sidney BurrusAs a part of collection: "Introduction to LabVIEW MathScript"

    Click the "NSF Partnership" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • National Instruments display tagshide tags

    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.

    Click the tag icon tag icon to display tags associated with this content.

Also in these lenses

  • Lens for Engineering

    This module is included inLens: Lens for Engineering
    By: Sidney Burrus

    Click the "Lens for Engineering" link to see all content selected in this lens.

  • NI Signal Processing display tagshide tags

    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.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

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. E-mail the authors

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.

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 LABVIEW MATHSCRIPT program 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 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

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

Content actions

Download 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 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