1 / 23

MATLAB DENC 2533 ECADD

MATLAB DENC 2533 ECADD. LAB 9. OUTLINE. INTRO MATLAB SYSTEM MATLAB WINDOW MATLAB IN MATHEMATICAL OPERATION GRAPHIC ON MATLAB MATLAB EDITOR FILE (M-file) PROGRAMMING IN MATLAB. Introduction. MATLAB stand for MATrix LABoratory . High performance language for technical computing.

Download Presentation

MATLAB DENC 2533 ECADD

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLABDENC 2533 ECADD LAB 9

  2. OUTLINE • INTRO • MATLAB SYSTEM • MATLAB WINDOW • MATLAB IN MATHEMATICAL OPERATION • GRAPHIC ON MATLAB • MATLAB EDITOR FILE (M-file) • PROGRAMMING IN MATLAB

  3. Introduction • MATLAB stand for MATrixLABoratory. • High performance language for technical computing. • It integrates computation, visualization and programming. • Typical uses in: • Math and computation • Algorithm development • Modeling, simulation and prototyping • Data analysis, exploration and visualization • Scientific and engineering graphics • Application development

  4. MATLAB System • Development environment – command window, command history, editor, debugger, browsers for help, workspace file. • MATLAB mathematical function library – function like sum, sine, cosine and complex arithmetic, matrix. • MATLAB language – high level matrix/array language with control flow statements, functions, data structure, I/O. • Graphics – presentation graphics, image processing, data visualization. • MATLAB application program interface (API) – a library that allows to write C and FORTRAN programs that interact with MATLAB.

  5. Starting MATLAB • When you start MATLAB, 4 windows appear by default: • MATLAB Command Window • Current Directory Window • Workspace Window • Command History Window

  6. 1) MATLAB Command Window • To communicate with MATLAB program, use MATLAB command window. • MATLAB display the prompt (>> ) to indicate that it is ready to receive instructions.

  7. ii) Current Directory Window • It is much like a file manager window. • Used to access files • For example: file.m – it will open file in Matlab editor.

  8. iii) Workspace Window • Display the variables created in the command window • Workspace refers to the names and values of any variable in use in the current work session.

  9. Command History Window • All the previous instruction/programming entered in MATLAB command window showed here • You can double click and drag the command into the MATLAB command window or Matlab editor.

  10. Entering Command and Expressions • Example of command s in Matlab Command Window: • >> x=[0:002:8]; • >> y=5*sin(x); • >> plot(x,y): • When you put semicolon (;) at the end of your command line, Matlab will not shows the answer of your commands/expressions. • Example of mathematical expressions in Matlab prompt without semicolon(;) : • >> 8/10 • ans = 0.8000 • >> 5*anw • ans = 4

  11. Variables • A variable in Matlab is a symbol used to contain a value. • When we do not specify a variable name for a result, Matlab uses the symbol ans as a temporary variable containing the most recent answer. • Scalar variable: • >> r=8/10 r = 0.8000 • >> s=5*r s = 4 • >> 3 + 9 ans = 12

  12. Variables (cont.) • Variable names must begin with a letter and must contain less than 32 characters; contain letter, digits, and underscore. • Matlab is case-sensitive, the following names represent different variables: speed, Speed, SPEED. • Special variables and built-in constants in matlab: • ans, i , j, inf, NaN, pi

  13. Scalar Arithmetic Operations:

  14. Commands for managing the MATLAB

  15. Computing with MATLAB • Matlab able to handle collection of numbers, called array. • Example of array variable: • >> x= [0 1 3 6]; % 4-sequence of array • >> u= [0 1; 2 1]; % 2x2 matrix • >> y= [0:0.01:2]; • >> length (y); % check total number of sequence-y • >> y(7); % check the value of y in array-7 • Define polynomial x2 + 2x + 1, to find roots of the polynomial: • >> a= [1, 2, 1]; • >> roots (a) • Answer: roots of a: x= -1 , x= -1 •  So, the polynomial a is (x+1)(x+1)

  16. Computing with MATLAB (cont.) • Built-in and User Defined Functions

  17. Matlab Scripting files & the Editor/Debugger • Matlab can perform operations in 2 ways: • Using Matlab Command Window • Using Editor/Debugger (.m file)

  18. MATLAB Editor M-file (.m) • All program and function files are saved using Matlab editor. • Writing M-files will enhance your problem solving productivity since many MATLAB commands can be run from one file without having to enter each command one-by-one at the MATLAB prompt. This way, corrections and changes can be made in the M-file and re-run easily. •  Using the MATLAB Script Editor (click FileNewM-file)

  19. Plotting with Matlab/Graphics • Matlab contains many powerful functions for easily creating plots of several different types. • Try this session: >> x=[0:0.001:10]; >> y=sin(2*x); >> figure(1); >> plot(x,y); >> xlabel(‘paksi-x’), ylabel(‘paksi-y’); >> title(‘plot y=sin 2x’);

  20. Plotting with Matlab/Graphics (cont.)

  21. PROGRAMMING IN MATLAB • Flow control: • if statement • if statements evaluates a logical expression and executes a group of statements when the expression is true. • Eg: If A > B ‘greater’ elseif A < B ‘less’ elseif A == B ‘equal’ else ‘unknown error’ end

  22. PROGRAMMING IN MATLAB (cont.) • for statement - for loop repeats a group of statements a fixed, predetermined number of times. • Eg: m = 0 for n = 3:32 m = m + n end m

  23. PROGRAMMING IN MATLAB (cont.) • while statement • while loop repeats a group of statements an indefinite number of times under control of a logical condition. • Eg: a = 0 b = 10 while b > a b = b – 1; end a b

More Related