# BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.

## Presentation on theme: "BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists."— Presentation transcript:

BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists

Ch.1: Introduction The objectives of this chapter are to enable you to use some simple MATLAB commands from the Command Window and to examine various MATLAB desktop and editing features. The name MATLAB stands for MATrix LABoratory. because the system was designed to make matrix computations particularly easy.

Cont. There are two essential requirements for successful MATLAB programming: - 1- You need to learn the exact rules for writing MATLAB statements. - 2- You need to develop a logical plan of attack for solving particular problems. This chapter is devoted mainly with an introduction to the first requirement.

1.1: Using MATLAB

Cont. Some Examples of Matlab Commands: >> 3-2 >> 2*3 >> 1/2 >> 2ˆ3 >> 2\1 >> 2.* 3 >> 1./ 2 >> 2.ˆ 3

Cont. How do you think MATLAB would handle 0/1 and 1/0 ? It gives you the answer “0” and “Inf.”. E.g. 13+Inf,29/inf. etc. What is NaN? It stands for Not-a-Number. It is the answer to calculations like 0/0.

Cont. Assign values to variables: >> a = 2 >> a = a * 10 >> b = 3; >> x = 2; y = 3; >> z = x + y

Cont. MATLAB has all of the usual mathematical functions. Examples: pi, sqrt(), sin(), etc. The exponential function e x is computed in MATLAB as exp(x). >> pi = 4?

Cont. >> u = 5 %u is called a scalar. >> x= 0 : 10 % x is called a vector(row vector). >> size(x), size(u) Other vectors can now be defined (or created) in terms of the vector x just defined. >> y = 2.* x >> w = y./ x

Cont. Drawing a graph of sin(): >> x = 0 : 0.1 : 10; >> z = sin(x); >> plot(x,z), grid

1.3.2 Saving a program: script files File -> New -> M-file / Script Write a program -> save it -> (program_name.m). A MATLAB program saved from the Editor with the extension.m is called a script file, or simply a script. If you enter the program name at the command-line prompt, MATLAB carries out each statement in the script file as if it were entered at the prompt. A script file may be listed in the Command Window with the command “type”. e.g. >> type program_name.

Cont. Ch.1 Important Notes: You can select (and edit) previous commands you have entered using Up-arrow and Down-arrow. MATLAB has a useful editing feature called smart recall. Just type the first few characters of the command you want to recall, e.g. type the characters 2* and press the Up-arrow key—this recalls the most recent command starting with 2*.

2.1.3 The workspace The command “who” lists the names of all the variables in your workspace. The command “whos” lists the size of each variable. The function “ans” returns the value of the last expression evaluated but not assigned to a variable. The Workspace Browser in the desktop provides a handy visual representation of the workspace. You can view and even change the values of workspace variables with the Array Editor.

2.1.3 The workspace All the variables you create during a session remain in the workspace until you clear them. You can clear all the variables by using the command line “clear”. A particular variable can be removed from the workspace, e.g. clear x. More than one variable can also be cleared, e.g. clear x y.

cont. “clc” (for clear command window ). “sin(pi/2)” is a function take the value of pi/2 Notice the difference between a function and a command in Matlab The line with the prompt (>>) is called the command line.

cont. You can quit MATLAB at any time with one of the following: - Select Exit MATLAB from the desktop File menu. - Enter quit or exit at the Command Window prompt. Do not click on the close box in the top right corner of the MATLAB desktop. This does not allow MATLAB to terminate properly and, on rare occasions, may cause problems with your computer operating software.

Download ppt "BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists."

Similar presentations