Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

- Matlab Basic Tutorial by Muhammad Rizwan 25432 views
- Matlab 1(operations on_matrix) by harman kaur 169 views
- Contoh program matlab by Zahra Doangs 19438 views
- Transient Responses (Laplace Transf... by School of Design ... 33072 views
- MATLAB Programs For Beginners. | Ab... by Abee Sharma 8867 views
- Introduction to Matlab by Amr Rashed 15678 views

994 views

Published on

Matlab Functions and types

Published in:
Engineering

No Downloads

Total views

994

On SlideShare

0

From Embeds

0

Number of Embeds

13

Shares

0

Downloads

81

Comments

0

Likes

5

No embeds

No notes for slide

- 1. 13033386-018 Umar Azeem University of Gujrat
- 2. A function is a MATLAB program that can accept inputs and produce outputs A function is a group of statements that together perform a task. Functions can accept more than one input arguments and may return more than one output arguments
- 3. Functions provide reusable code Use same code in more than one place in program without rewriting code Reuse code by calling in different programs
- 4. Built in Function User define Function
- 5. Built in Function
- 6. + Plus; addition operator. - Minus; subtraction operator. * Scalar and matrix multiplication operator. .* Array multiplication operator. ^ Scalar and matrix exponentiation operator. .^ Array exponentiation operator. Left-division operator. / Right-division operator. . Array left-division operator. ./ Array right-division operator.
- 7. : Colon; generates regularly spaced elements and represents an entire row or column. ( ) Parentheses; encloses function arguments and array indices; overrides precedence. [ ] Brackets; enclosures array elements. ., Comma; separates statements and elements in a row. ; Semicolon; separates columns and suppresses display. % Percent sign; designates a comment and specifies formatting. = Assignment (replacement) operator.
- 8. clc -Clears Command window. Clear- Removes variables from memory. exist -Checks for existence of file or variable. Global- Declares variables to be global. help -Searches for a help topic. Lookfor- Searches help entries for a keyword. quit -Stops MATLAB. who -Lists current variables. whos -Lists current variables (long display).
- 9. Cd-Changes current directory. Date-Displays current date. Delete-Deletes a file. Diary-Switches on/off diary file recording. dir-Lists all files in current directory. Load-Loads workspace variables from a file. Path-Displays search path. Save-Saves workspace variables in a file.
- 10. max(x) min(x) mean(x) median(x) sum(x)
- 11. sin(x) sine cos(x) cosine tan(x) tangent asin(x) inverse sine sinh(x) hyperbolic sine asinh(x) inverse hyperbolic sine sind(x) sine with degree input asind(x) inverse sin with degree output
- 12. User define Function
- 13. Identify the function Decide the function name Decide the input variables Decide the output variables File name must be the function name.
- 14. function[a, b, c]= basicmath(x,y) %BASICMATH Basic Mathematical function % basicmath(x,y) is a sample matlab function to perform % basic mathematical operations on input variables x & y % outputs of the function are sum, difference and product of input arguments. a = x + y; b = x – y; c = x * y; 14 Output arguments Executable code Comments about the function Name of the function Input arguments declaration statement
- 15. The declaration statement function is used to define the file as a function. It must be typed in lower case letters. Input arguments • Can be zero or more input arguments. Output arguments • Types inside the square brackets [ ] Give a meaningful variable name.
- 16. • The function have only one out put you don’t need to put it inside the square brackets [ ] Example: The function in a file named average.m that accepts an input vector, calculates the average of the values, and returns a single result. function y = average(x) y = sum(x)/length(x); end
- 17. When there are more than one output arguments put them in a square bracket. Example function[a, b, c]= basicmath(x,y) a = x + y; b = x – y; c = x * y;
- 18. A function can be called from the command window or inside a script or function. To run a function in command window, just type the name of comment with proper input and output arguments • For example consider the function basicmath >> [a,b,c] = basicmath (2,3) a = 5 b = -1 c = 6
- 19. Function name and file name must be same. Unlike other programming languages, Function in MATLAB can return more than one value. Syntax: function outputs=function_name(inputs) There is no starting and ending curly braceS to enclose the body of function, instead, there is an end statement which signifies end of function.
- 20. To run a function we type a function name with valid arguments in command window area. If function returns two or more ouputs,to see all the outputs, we must not put semicolon after the output statement. Note: if we put semicolon, we will see only the first output.
- 21. MATLAB contains a wide array of predefined functions •Elementary Math Functions •Trigonometric Functions •Data Analysis Functions •Random Numbers •Complex Numbers
- 22. Thank You

No public clipboards found for this slide

Be the first to comment