0% found this document useful (0 votes)
42 views16 pages

University of Engineering & Technology Lahore: Experiment

The document describes an experiment using MATLAB/MATLAB Refresher software. It provides an overview of MATLAB's capabilities and interface. The procedure demonstrates basic MATLAB commands like arithmetic operations, assigning variables, changing output formats, and using built-in math functions. It includes examples of solving simple problems in the MATLAB Command Window.

Uploaded by

Ghulam Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views16 pages

University of Engineering & Technology Lahore: Experiment

The document describes an experiment using MATLAB/MATLAB Refresher software. It provides an overview of MATLAB's capabilities and interface. The procedure demonstrates basic MATLAB commands like arithmetic operations, assigning variables, changing output formats, and using built-in math functions. It includes examples of solving simple problems in the MATLAB Command Window.

Uploaded by

Ghulam Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Reg.

# 2018-EE-427

University of Engineering & Technology Lahore


Experiment # 1:
Title: Starting with MATLAB/MATLAB Refresher

Equipment Required: Personal computer (PC) with windows operating system


MATLAB software

Theory: -
MATLAB is a powerful computing system for handling the calculations involved in
problems
scientific and engineering . The name MATLAB stands for Matrix Laboratory,
because the system was designed to make matrix computations particularly easy. One of
the many things about MATLAB (and which distinguishes it from many other computer
programming systems, such as C++ and Java) is that you can use it interactively. This
means you type some commands at the special MATLAB prompt, and get the answers
immediately. The problems solved in this way can be very simple, like finding a square
root, or they can be much more complicated, like finding the solution to a system of
differential equations. For many technical problems you have to enter only one or two
commands, and you get the answers at once.

MATLAB WINDOWS: -

Window Purpose
Command Window Main window, enters variables, runs programs.
Figure Window Contains output from graphic commands.
Editor Window Creates and debugs script and functon fles.
Help Window Provides help informaton.
Launch Pad Window Provides access to tools, demos, and documentaton.
Command History Window Logs commands entered in the Command Window
Workspace Window Provides informaton about the variables that are used.
Current Directory Window Shows the fles in the current directory

Workspace Window
Command Window
Command
History Window

Procedure: -

1) To start MATLAB from Windows, double-click the MATLAB icon on your


Windows desktop. When MATLAB starts, the MATLAB desktop opens as shown
in Figure 1.1. The window in the desktop that concerns us for this experiment is
the Command Window, where the special >> prompt appears. This prompt means
that MATLAB is waiting for a command. 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.
2) Once you have started MATLAB, try the following exercises in the Command
Window.
(a) Type 2+3 after the >> prompt, followed by Enter, i.e. press the Enter key, as
indicated by <Enter>, below:
>>2+3 <Enter>
Commands are only carried out when you press Enter. The answer in this
case is, of course, 5.
(b) Next try the following:
>>3-2 <Enter>
>>2*3 <Enter>
>>1/2 <Enter>
>> 2ˆ3 <Enter>
>>2\1 <Enter>
symbols *, / and ˆ, are multiplication, division and exponentiation. The backslash
means the denominator is to the left of the symbol and the numerator is to the
right of the symbol; the result for the last command is 0.5. This operation is
equivalent to 1/2.
3) Assign values to variables to do arithmetical operations with the variables.
(a) Enter the command a = 2, i.e. the MATLAB command line should look
like this:
>>a = 2 <Enter>
The symbol a is called a variable. This statement assigns the value of 2 to a.
(b)Now enter the statement
>>b = 3; <Enter>
The semicolon (;) prevents the value of b from being displayed.
4) The output format is fixed-point with 4 decimal digits (called short), which is the
default format for numerical values. The format can be changed with the format
command. Once the format command is entered, all the output that follows is
displayed in the specified format. Several of the available formats are listed and
described in Table below.

Display formats
Command Descripton Example
format short Fixed-point with 4 decimal digits for: >> format short
0.001 ≤ number ≤1000 Otherwise display >> 290/7 ans =
format short e. 41.4286
format long Fixed-point with 14decimal digits. >> format long >>
290/7
ans = 41.428571428571431
format short e Scientfc notaton with 4 decimal digits. >> format short e
>> 290/7
ans = 4.1429e+001
format long e Scientfc notaton with 15 decimal digits. >> format long e >>
290/7
ans =
4.142857142857143e+001
format short g Best of 5-digit fxed or foatng point. >> format short g
>> 290/7
ans = 41.429
format long g Best of I5-digit fxed or foatng point. >> format long g >> 290/7
ans = 41.4285714285714

format bank Two decimal digits. >> format bank


>> 290/7 ans =
41.43

5) ELEMENTARY MATH BUILT-IN FUNCTIONS


In addition to basic arithmetic operations, expressions in MATLAB can
include functions. MATLAB has a very large library of built-in functions. A
function has a name and an argument in parentheses. For example, the function
that calculates the square root of a number is sqrt(x). Its name is sqrt, and the
argument is x.

Elementary math functions

Functon Descripton Example


sqrt(x) Square root. >> sqrt(81)
ans = 9.00
exp(x) Exponental (ex). >> exp(5) ans
= 148.41
abs (x) Absolute value. >> abs (-24)
ans = 24.00
log (x) Natural logarithm. >> log(1000)
Base e logarithm (In). ans = 6.91
log10(x) Base 10 logarithm. >> log10(1000)
ans = 3.00
factorial (x) The factorial functon x! >> factorial (5)
(x must be a positve ans = 120.00
integer.)

Functon Descripton Example


sin(x) Sine of angle x (x in >> sin(pi/6)
radians). ans = 0.5000
cos(x) Cosine of angle x (x in >> cos(pi/6)
radians). ans = 0.8660

tan (x) Tangent of angle x (x in >> tan(pi/6)


radians). ans = 0.5774
cot (x) Cotangent of angle x (.x in >> cot(pi/6)
radians). ans = 1.7321

Rounding functons
Functon Descripton Example
round (x) Round to the nearest >> round (17/5)
integer. ans = 3
fx(x) Round towards zero. >> fx (13/5)
ans = 2
ceil(x) Round towards infnity. >> ceil (11/5)
ans = 3
foor (x) Round towards minus >> foor(-9/4)
infnity. ans = -3
rem(x,y) Returns the remainder >> rem(13,5)
after x is divided by y. ans = 3
sign(x) Signum functon. Returns 1 >> sign(5)
if ans = 1
x > 0 , -1 if x < 0, and 0 if x =
0

Rules About Variable Names


Variable names:
· Can be up to 63 characters long
· Can contain letters, digits, and the underscore character ·
Must begin with a letter.
· MATLAB is case sensitive; it distinguishes between uppercase and lowercase
letters. For example, AA, Aa, aA, and aa are the names of four different variables.
· Avoid using the names of a built-in function for a variable (i.e. avoid using: cos,
sin, exp, sqrt, etc.). Once a function name is used to define a variable, the function
cannot be used. Problems:-
Solve the following problems in the Command Window.
Q-1: Calculate;

Q-2: Defne the variable x as x = 13.5, then evaluate:


Q-3: Defne the variable x and z as x = 9.6, and z=8.1, then evaluate.

Q-4: Defne the variable a, b, c, and d as:


a = 15.62, b =-7.08, c = 62.5 and d = 0.5(ab-c)
Evaluate:

Q-1: Calculate;
Software:

Theoretical calculation:
Software:
Theoretical calculation:
Software:

Theoretical calculation:

Software:
Theoretical calculation:

Q-2: Defne the variable x as x = 13.5, then evaluate:


Software:

Theoretical calculation:

Q-3: Defne the variable x and z as x = 9.6, and z=8.1, then evaluate.
Software:

Theoretical calculation:

Q-4: Defne the variable a, b, c, and d as:


a = 15.62, b =-7.08, c = 62.5 and d = 0.5(ab-c)
Evaluate:
Software:

Theoretical calculation:
Conclusion:

In this lab we have learn how to use MATLAB for the manipulation of basic
math operation as well as to solve the complex problems related to different fields of
engineering. MATLAB is useful math tool as it is capable of solving matrix, derivative,
integration and many more operation on ODEs with ability of making graphs of functions with
respect to time or other independent variables.

You might also like