Download presentation
Presentation is loading. Please wait.
Published byGodwin Casey Modified over 9 years ago
1
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university
2
Content MATLAB What is MATLAB? The MATLAB desktop invironment. MATLAB as calculator. Variables. Algorithm Interduction to m-file function.
3
Outline MATLAB What is MATLAB? The MATLAB desktop invironment. MATLAB as calculator. Variables. Algorithm Interduction to m-file function.
4
MATLAB is a mathematical and graphical software package with numerical, graphical and programming capabilities. it has built-in functions to perform many operations. MATLAB
5
Outline What is MATLAB? The MATLAB desktop invironment. MATLAB as calculator. Variables. Algorithm Interduction to m-file function. MATLAB
7
Command window: Type your instructions here and press ENTER to execute them. MATLAB
8
Example: Declare a column matrix with values 1,2 and 3. MATLAB
9
Command history: a list of instructions executed by MATLAB is shown here. MATLAB
10
Workspace: shows a list of variables created by MATLAB. As you can see, the value of ‘aaa’ is shown. MATLAB
11
Another way to create a variable Is to press this button. MATLAB
12
MATLAB will prompt you to enter the variable name. MATLAB
13
As you can see, the variable name has been changed to bbb. MATLAB
14
To assign a value to bbb, you can do it in two ways: 1) Using the command window. 2) Or by double clicking on bbb. MATLAB
15
To clear all variables from memory and close all figures, use the clear, close all command. MATLAB
16
As you can see, all workspace variables are deleted when you execute this command. MATLAB
17
To clear the command window, use the clc (clear console) command. MATLAB
18
As you can see, all console entries are deleted when you execute this command. MATLAB
19
If you want to see help, you can type help at the command window. MATLAB
20
Outline What is MATLAB? The MATLAB desktop invironment. MATLAB as calculator. Variables. Algorithm Interduction to m-file function. MATLAB
21
Operators + addition + a+b - subtraction- a-b * multiplication* a*b / Division(left) / a/b \ Division(right)\ a\b (b a) ^ power^ a^b MATLAB
22
Operator precedence rules 1.() parentheses. 2.^ power. 3.- negation. 4.*/ \ all multiplication and division. 5.+ - addition and subtraction. MATLAB
23
Examples >> 6*5 ans = 30 >> 17/5 ans = 3.4000 >> ans ans = 3.4000 >> 6*5 ans = 30 >> 17/5 ans = 3.4000 >> ans ans = 3.4000 >> x=6*5 x= 30 >> y=17/5; >> y y= 3.4000 >> z=x+y z= 33.4000 >> who Your variables are: xyz >> x=6*5 x= 30 >> y=17/5; >> y y= 3.4000 >> z=x+y z= 33.4000 >> who Your variables are: xyz MATLAB
24
Some functions in MATLAB exp(x) e x sin(x) sin x asin(x) sin -1 x log(x) ln x log10(x) log x sqrt(x) abs(x) |x| sum(x) pi i,j imaginary unit NaN Not-a-Number Inf MATLAB
25
Example >>y=x^0.5; >>y=x^(1/2); >>y=sqrt(x); MATLAB
26
Outline What is MATLAB? The MATLAB desktop invironment. MATLAB as calculator. Variables. Algorithm Interduction to m-file. MATLAB
27
Variables Creating Variables: – Names Can be any string of upper and lower case letters along with numbers and underscores but it must begin with a letter Reserved names are IF, WHILE, ELSE, END, SUM, etc. Names are case sensitive – Value This is the data the is associated to the variable; the data is accessed by using the name. – Variables have the type of the last thing assigned to them Re-assignment is done silently – there are no warnings if you overwrite a variable with something of a different type. MATLAB
28
Outline What is MATLAB? The MATLAB desktop invironment. MATLAB as calculator. Variables. Algorithm Interduction to m-file MATLAB
29
Definition of algorithm An algorithm is the sequence of steps needed to solve a problem. MATLAB
30
Outline What is MATLAB? The MATLAB desktop invironment. MATLAB as calculator. Variables. Algorithm Interduction to m-file. MATLAB
31
To create an m-file, 1) type edit at the command window, or 2) Press this button. MATLAB
32
The previous command will display the editor window. The editor creates an m-file that can be used to write your MATLAB programs. MATLAB
33
To execute a program, press the RUN button. MATLAB
34
End the first part
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.