Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Introduction To Matlab-Lecture 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

Introduction to Matlab

Presented by
Z. L. A
What is Matlab?

 MATLAB is one of a number of commercially available, sophisticated


mathematical computation tools.
 The Matlab can only perform basic mathematical computations but also
handle symbolic calculations and more complicated mathematical
processes, such as matrix manipulation.
 In many engineering computations, the MATLAB is now replacing in the
place of traditional computer programming because it is so easy and
useful.
 It becomes a standard tool for engineers and scientists.
 Although it often need to write scripts to do for your special purposes,
the Matlab users are not need to be programmers.
 The purposes of using Matlab are for computations, problem solving,
simulations and analysis, not for software development.
Matlab Desktop

Workspace / Current Command


Directory
Window

Command
History
Preparation Before Font Name Font size
Basic Command

No Command Description
1 clc Clear screen
2 clear Clear all variables in the workspace
3 close all Close all figures
4 quit or exit Exit Matlab
5 % comment
6 edit Open Matlab script editor
Is Matlab calculator?

Let
At first, we introduce a simple
calculation of volume of sphere.
(v=4/3 πr3)

Formula to be calculate:
v=4/3 πr3, r = 2

Result is v = 33.5103
Is Matlab calculator?

Next,
Formula : t = (1/(1+px))^k ,
p, x, k are scalars.

When p=2, x=8, k=0.2,


Is Matlab calculator?
Math; MATLAB Description
formula command
𝑥 sqrt(x) Compute the square root of x
𝑒𝑥 exp(x) Compute the exponential value
of x
loge x (or) log(x) Compute the natural logarithm
lne x of x with base e
log x Log10(x) Compute the natural logarithm
of x with base 10
- rem(x,y) Compute remainder of x/y.
- abs(x) Compute absolute of x
- round(x) Round x to the nearest integer
Is Matlab calculator?
Is Matlab calculator?
For the Complex Number Computation
For the Complex Number Computation
For the Complex Number Computation

input Process output


Writing Scripts
Writing Scripts
clear;
clc;
r = input('Enter radious of cylinder in feet: ');
h = input('Enter height of cylinder in feet: ');

V = pi*r*r*h;

fprintf('The volume of the cylinder is :%f cubic feet\n',V);


str=strcat('The volume of the cylinder is: ',num2str(V),' cubic feet');
msgbox(str);
Control Flags in MATLAB
if(expression1)
statement1
elseif(expression 2) a=input('enter a number: ');
statement2
. if(a<0)
. display(' the number is negative');
. elseif(a>0)
. display(' the number is positive');
elseif(expression N) else
statement N display(' the number is zero');
else end
statement N+1
Operators in Matlab
Operators in Matlab
Loops in MATLAB
For Loop
Loops in MATLAB
For Loop
Loops in MATLAB
While Loop
Functions in MATLAB
 In a complex and large program, to be clear codes and easy for maintenance, the
large program is divided into sub function programs.
 This technique is usually called “divide and conquer”.
 Actually, a function is a partial part of main program. In MATLAB, the function
file is also a M-file but it cannot run. To run the function file, a M-file of main
program code is needed.
Functions in MATLAB

Click there to create function file


Functions in MATLAB
When created function file is appeared, change name, argument and return you want.
Functions in MATLAB
Example
Functions in MATLAB
Functions in MATLAB
Functions in MATLAB
Assignments
1. To find the volume of the cylinder tube as shown in figure, write area function
script and main script codes. In the figure, inner cylinder tube is hollow. Let D =
3 m, d = 1 m, h = 2.5 m and H = 5 m.
Assignments
Assignments

Lecture download link:


https://drive.google.com/open?id=1upDUhloPSa5vzq-kasbWq2z0giupilxc

You might also like