You are on page 1of 20

Umm Al-Qura University

College of Engineering and Islamic Architecture

Department of Electrical Engineering

EE3001-Engineering Numerical Methods

Lab Work #2: MATLAB BASICS I

Prepared by:
Ghassan alhazmi
444005350
2023-09-9
OBJECTIVES
Become familiar with m-files.

Here is an example of a small script file


Inline functions and the feval command

You can evaluate this function in a usual way


Note that this function also works with arrays. Let

and
Then

For the later use let us mention briefly a concept of the string in MATLAB. The
character string is a text surrounded by single quotes. For instance,
To illustrate the use of the command feval let us take a closer look at the code in the
m-file mylcm
Command feval checks whether or not both input arguments are integers. If this
condition is satisfied, then the least common multiple is computed using the formula
mentioned earlier, otherwise the error message is generated. Note use of the
command error, which takes as the argument a string. Function that is executed
twice in the body of the function mylcm is named isint
realmin is the smallest positive real number on your computer
The input parameters a and b can be arrays of the same dimension. This is
possible because the dot operator proceeds certain arithmetic operations in the
command that defines the variable y. In this example we will integrate the sine
function over two intervals whose end points are stored in the arrays a and b,
where
Lab review Questions:
Q1. . Evaluate the following MATLAB expressions yourself before
checking the answers in MATLAB:
Q2:
a)
b)

c)
Q3

a)

b)
c)

d)
e)

f)
Q4

Use MATLAB array operations to do the following:


1)

2)
3)

4)

You might also like