Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Matlab

Similar presentations


Presentation on theme: "Introduction to Matlab"— Presentation transcript:

1 Introduction to Matlab
By: Maha AlMousa

2 Outline: What is MATLAB? MATLAB desktop environment. Variables.
Operations. Definition of algorithms. Introduction to M-files.

3 What is Matlab? MATLAB is an interactive system for numerical computation. MATLAB is a modern programming language and problem-solving environment.

4 MATLAB desktop environment.
Command Window type commands

5 Example

6 Command History view past commands save a whole session using diary

7 Workspace View a list of variables created by MATLAB.
Double click on a variable to see it in the Array Editor

8 Another way to create a variable

9 To assign a value to bbb

10 MATLAB special variables

11 Operators (arithmetic)
+ addition / division - Subtraction ^ power * multiplication

12 Operator precedence rules
() parentheses. ^ power. - negation. */ \ all multiplication and division. + - addition and subtraction.

13 Example

14 Scripts and functions Scripts functions
Both scripts and functions allow you to reuse sequences of commands by storing them in program files Scripts they store commands exactly as you would type them at the command line the simplest type of program functions more flexible and more easily extensible.

15 Some functions in MATLAB
exp(x) 𝑒 𝑥 sin(x) sin 𝑥 asin(x) 𝑠𝑖𝑛 −1 𝑥 log(x) ln 𝑥 log10(x) log 𝑥 sqrt (x) 𝑥 abs(x) sum(x) pi 𝜋 NaN Not-a-Number Inf i,j imaginary unit

16 Example >>y=x^0.5; >>y=x^(1/2); >>y=sqrt(x);

17 Creating Variable Names Value
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. Value This is the data the is associated to the variable; the data is accessed by using the name.

18 Definition of algorithms.
An algorithm is the sequence of steps needed to solve a problem.

19 Introduction to m-file

20 The previous command will display the editor window
The previous command will display the editor window. The editor creates an m-file that can be used to write your MATLAB programs.

21 To execute a program

22 Example Create a script in a file named triarea.m that computes the area of a triangle: b = 5; h = 3; a = 0.5*(b.*h) After you save the file, you can call the script from the command line: triarea a =

23 function a = triarea(b,h)
end

24

25 Home Work 1. Some calculations on the command window.
2. Create an M-file. Deadline: The tutorial lecture on Sunday H

26


Download ppt "Introduction to Matlab"

Similar presentations


Ads by Google