Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud...
-
Upload
godwin-casey -
Category
Documents
-
view
225 -
download
0
Transcript of Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud...
![Page 1: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/1.jpg)
Interduction to MATLAB
•Manal AlotaibiMathematics departmentCollege of science King saud university
![Page 2: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/2.jpg)
Content
MATLAB
What is MATLAB?The MATLAB desktop invironment.MATLAB as calculator.Variables.AlgorithmInterduction to m-file function.
![Page 3: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/3.jpg)
Outline
MATLAB
What is MATLAB?The MATLAB desktop invironment.MATLAB as calculator.Variables.AlgorithmInterduction to m-file function.
![Page 4: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/4.jpg)
• MATLAB is a mathematical and graphical software package with numerical, graphical and programming capabilities.
• it has built-in functions to perform many operations.
MATLAB
![Page 5: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/5.jpg)
Outline What is MATLAB?The MATLAB desktop invironment.MATLAB as calculator.Variables.AlgorithmInterduction to m-file function.
MATLAB
![Page 6: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/6.jpg)
MATLAB
![Page 7: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/7.jpg)
Command window: Type your instructions here and press
ENTER to execute them.
MATLAB
![Page 8: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/8.jpg)
Example: Declare a column matrix withvalues 1,2 and 3.
MATLAB
![Page 9: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/9.jpg)
Command history: a list of instructions executed by MATLAB is shown here .
MATLAB
![Page 10: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/10.jpg)
Workspace: shows a list of variables created by MATLAB.
As you can see, the value of ‘aaa’is shown .
MATLAB
![Page 11: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/11.jpg)
Another way to create a variable Is to press this button .
MATLAB
![Page 12: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/12.jpg)
MATLAB will prompt you to enter the variable name .
MATLAB
![Page 13: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/13.jpg)
As you can see, the variable name has been changed to bbb .
MATLAB
![Page 14: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/14.jpg)
To assign a value to bbb, you can do it intwo ways: 1) Using the command window.
2 )Or by double clicking on bbb .
MATLAB
![Page 15: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/15.jpg)
To clear all variables from memory and close all
figures, use the clear, close all command.
MATLAB
![Page 16: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/16.jpg)
As you can see, all workspace variables are deleted when you execute this command.
MATLAB
![Page 17: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/17.jpg)
To clear the command window,use the clc (clear console) command.
MATLAB
![Page 18: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/18.jpg)
As you can see, all console entries are deleted when
you execute this command.
MATLAB
![Page 19: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/19.jpg)
If you want to see help,you can type help at the
command window.
MATLAB
![Page 20: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/20.jpg)
Outline
What is MATLAB?The MATLAB desktop invironment.MATLAB as calculator.Variables.AlgorithmInterduction to m-file function.
MATLAB
![Page 21: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/21.jpg)
Operators
•addition + a+b•subtraction-a-b•multiplication*a*b•Division(left) / a/b•Division(right)\ a\b (ba)•power^a^b
MATLAB
![Page 22: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/22.jpg)
Operator precedence rules
1. () parentheses.2. ^ power.3. - negation.4. */ \ all multiplication and division.5. + - addition and subtraction.
MATLAB
![Page 23: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/23.jpg)
Examples >>6*5
ans= •30 >>17/5
ans= 3.4000
>>ansans=
3.4000
>>6*5ans= •30 >>17/5
ans= 3.4000
>>ansans=
3.4000
>> x=6*5x=
30>> y=17/5;>> yy=
3.4000>> z=x+yz=
33.4000>> whoYour variables are:x y z
>> x=6*5x=
30>> y=17/5;>> yy=
3.4000>> z=x+yz=
33.4000>> whoYour variables are:x y z
MATLAB
![Page 24: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/24.jpg)
Some functions in MATLAB• exp(x) ex
• sin(x) sin x• asin(x) sin-1x• log(x) ln x• log10(x) log x• sqrt(x)• abs(x) |x|• sum(x) ix
• pi p• i,j imaginary unit• NaN Not-a-Number• Inf
MATLAB
![Page 25: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/25.jpg)
Example
y x>>y=x^0.5;>>y=x^(1/2);>>y=sqrt(x);
MATLAB
![Page 26: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/26.jpg)
Outline
What is MATLAB?The MATLAB desktop invironment.MATLAB as calculator.Variables.AlgorithmInterduction to m-file .
MATLAB
![Page 27: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/27.jpg)
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
![Page 28: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/28.jpg)
Outline
What is MATLAB?The MATLAB desktop invironment.MATLAB as calculator.Variables.AlgorithmInterduction to m-file
MATLAB
![Page 29: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/29.jpg)
Definition of algorithm
• An algorithm is the sequence of steps needed to solve a problem.
MATLAB
![Page 30: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/30.jpg)
Outline
What is MATLAB?The MATLAB desktop invironment.MATLAB as calculator.Variables.AlgorithmInterduction to m-file .
MATLAB
![Page 31: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/31.jpg)
To create an m-file, 1) type edit at the command window, or
2 )Press this button.
MATLAB
![Page 32: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/32.jpg)
The previous command willdisplay the editor window.
The editor creates an m-filethat can be used to write
your MATLAB programs .
MATLAB
![Page 33: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/33.jpg)
To execute a program, pressthe RUN button.
MATLAB
![Page 34: Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.](https://reader036.fdocuments.us/reader036/viewer/2022081506/5697bfbd1a28abf838ca23de/html5/thumbnails/34.jpg)
End the first part