EGR101: Introduction to Engineering Design - Module on Engineering Computing

 

MATLAB as an Interactive Computing Environment

 

So what’s MATLAB anyway?

MATLAB is both a computer programming language and an interactive software or computing environment. Deriving its name from the original terms MATrix LABoratory, it is now one of the most popular languages for developing computational solutions to engineering problems.  Its usual market competitors include MATHCAD, MAPLE and MATHEMATICA which all have their own attractions and disadvantages. They have effectively displaced traditional languages such as Visual Basic, Fortran, Pascal and C in many areas and provide an alternative tool to more current languages such as C++ and Java for “hard core” engineering computations.

 

The term MATrix from which the MAT in MATLAB is derived, denotes a group of numbers in a special arrangement.   Matrices are formally treated in a mathematics course called Linear Algebra.   A related concept is that of an array.  In computer programming, the term array means some group of numbers assigned to a single variable name stored on a computer.   One of the powerful features of MATLAB is that it lets you easily operate on entire arrays of numbers with a command as simple as one you would use for individual scalar values.

 

The term LABoratory, which provides the LAB in MATLAB, represents an exploratory environment in which engineering computations provide a tool both to investigate engineering problems and design and evaluate potential solutions. In essence, it is a non-catastrophic, experimental environment used pervasively to explore new ideas and investigate possible causes and solutions to complex problems. MATLAB is so popular an engineering tool because of thirty years of investment in the development of specialized toolboxes that implement common mathematical algorithms in different fields of study. Some of these are used to develop the MATLAB demo programs that we will access today.

 

Simply put, MATLAB is a computer programming language and computing environment designed for the easy manipulation and display of groups of numbers.

 

Working with MATLAB at an interactive level

You will find MATLAB in the popup menu of your PC on all School of Engineering computers. Unlike the Microsoft products however that are licensed campus-wide, MATLAB is licensed on a per seat basis and is not available for distribution across campus. A Student Version is available for about $100 (in the UD Computer Store) and will typically do anything you need in your undergraduate education…and then some. Open up MATLAB now and we’ll explore MATLAB at the interactive level.

 

·       The MATLAB prompt (») is shown in the example commands typed below. Almost all MATLAB commands and functions can be used interactively, including the ones that you will write over the next few weeks. They are executed simply by typing the command inside the MATLAB command window after the prompt.

·       Let’s type the following commands and look at what’s happening.

 

>>     8/10

>>     pi

>>     3+5

>>     2*pi*(8/10)

>>     r=8/10

>>     s=2*pi*r

>>     v=sin(s)

 

These are examples of assignment statements in MATLAB. They each assign a numerical value to a variable in MATLAB.  Multiply is signified with *, divide with /, and addition with +.  We will say more about these operators in Chapter 2.

·       In many instances, you will have a large number of variables defined in MATLAB. These reside in the MATLAB workspace and you need to be able to keep track of them.  We can do this by opening the workspace browser by selecting the Show Workspace option from the File menu in the MATLAB command window (or click on the yellow grid icon at the top of the command window).

·       MATLAB allows one to easily evaluate and graph mathematical functions. Type the following commands in the MATLAB command window. These commands construct a simple xy-plot with an appropriate title and labels.  Note that the variables, which represent arrays, now contain multiple values (not individual numbers like above).

 

>>     x=[0:1:10]

>>     y=2*x+3

>>     plot(x,y)

>>     title(‘Plot of y=2x+3’)

>>     xlabel(‘x’)

>>     ylabel(‘y’)

>>     grid

 

·       Let’s try plotting another function…

 

>>     x=[0:.01:10];

>>     y=sin(x);

>>     plot(x,y)

>>     xlabel(‘x’)

>>     ylabel(‘y’)

>>     grid

·       Note that putting a semicolon at the end of a statement indicates that MATLAB should NOT print the content of that variable or array.  An assignment command with no semicolon will return the contents of the array at the command line (it prints the variable by default).  Semicolons can also be used to separate multiple commands, which may be types on the same line.

·       Lastly, type the command demo at the command prompt and explore some of the features of MATLAB yourself. I’ll see you next time…

 

Before then:

Read Chapter 1 of the course textbook. We’ll begin to work from this material next time.

 

 

 

This document was originally created by Dr. Malcolm Daniels and has been adapted here by Dr. Russell Hardie.