0% found this document useful (0 votes)
17 views

SME1013 Matlab Functions

The document discusses MATLAB functions and files. It covers built-in functions, anonymous functions, and user-defined functions. It provides examples and explanations of each.

Uploaded by

khalil alhatab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

SME1013 Matlab Functions

The document discusses MATLAB functions and files. It covers built-in functions, anonymous functions, and user-defined functions. It provides examples and explanations of each.

Uploaded by

khalil alhatab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lecture 15a

MATLAB: Functions & Files

Dr M Kasim A Jalil
Faculty of Mechanical Engineering
UTM
Built-in Functions

 exp(x), sqrt(x), log(x), log10(x), cos(x),sin(x),acos(x)….


 Refer to table 3.1-1 & 3.1-2 pg 142 & 146

© Dr. MKAJ, FKM, UTM


Anonymous Functions
 Creating a function at the command prompt
 Syntax
function_handle = @(arglist) expr
where - arglist is a comma-separated list of input arguments
- expr is any single valid MATLAB expression
 Example
>> sqrtsum = @(x,y) sqrt(x.^2 + y.^2);
>>sqrtsum (3, 4)
ans =
5

© Dr. MKAJ, FKM, UTM


User-Defined Functions

 Syntax
function [output variables] = function_name (input variables)
definition of variables
 Example
function z = fun (x,y) >>w=fun(3,7)

u= 3*x; w=
303
z= u + 6*y.^2

© Dr. MKAJ, FKM, UTM


A fence around a field is shaped as shown in Figure P25. It consists of a rectangle of
length L and width W and a right triangle that is symmetric about the central horizontal
axis of the rectangle. Suppose the width W is known (in meters) and the enclosed area A
is known (in square meters). Write a MATLAB script file in terms of the given variables
W and A to determine the length L required so that the enclosed area is A. Also
determine the total length of fence required. Test your script for the valuesW = 6 m and
A =80 m2.

© Dr. MKAJ, FKM, UTM

You might also like