matlab_functions

# matlab_functions - Introduction to MATLAB MATLAB Functions...

This preview shows pages 1–10. Sign up to view the full content.

Virginia Polytechnic Institute and State University 1 of 31 Introduction to MATLAB MATLAB Functions Dr. Trani Civil and Environmental Engineering Virginia Polytechnic Institute and State University Spring 2001

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Virginia Polytechnic Institute and State University 2 of 31 Purpose of this Section To illustrate how MATLAB can be extended using functions To understand some of the data structures in MATLAB To understand some of the language speciﬁc features of the language
Virginia Polytechnic Institute and State University 3 of 31 MATLAB Functions Provide the highest degree of functionality in the language Function ﬁles in MATLAB are equivalent to subroutines in FORTRAN, functions in C, and procedures in Pascal Function ﬁles constitute the basis for complex programs and model prototyping Functions can be proﬁled (statistics can be obtained in their execution times line by line)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Virginia Polytechnic Institute and State University 4 of 31 Functions in MATLAB Typical framework for functions Good to avoid tedious code repetitions Main Routine call to fn 1 call to fn 2 fn 1 fn 2 script script
Virginia Polytechnic Institute and State University 5 of 31 General Syntax for Functions in MATLAB function [output var.] = function_name (input var.) The word function should always be present and typed in lowercase The output variable list is optional The function_name should be the same as the ﬁle name (except for the .m termination) containing the function script - A function called atmosphere should reside inside an M- ﬁle called atmosphere.m

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Virginia Polytechnic Institute and State University 6 of 31 Local vs. Global Variables Function ﬁles can incorporate two types of variables: - Local - Global Local variables exist inside the function that uses them. All variables deﬁned inside a function are local unless otherwise deﬁned Global variables are shared among various functions and are deﬁned as such in all function ﬁles where they are expected to be used - global x y z - This statement deﬁnes 3 global variables x,y, and z
Virginia Polytechnic Institute and State University 7 of 31 A Simple Function in MATLAB An empirical formula to estimate the pavement thickness is known to be: where: is the design pavement thickness (in inches) is the equivalent single wheel load of the aircraft tires on the pavement (in pounds) is the single tire contact area (in 2 ) t P 8.1 CBR ( 29 ------------------------ A π --- + = t P A

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Virginia Polytechnic Institute and State University 8 of 31 is the California Bearing Ratio (dimensionless) which measures the shearing strength of the soil (compared with the characteristics of crushed rock) and is 3.141592. . CBR π
Virginia Polytechnic Institute and State University 9 of 31 MATLAB Implementation (thickness.m) % Function to estimate the pavement thickness % of a ﬂexible pavement % Input arguments: % load = single wheel equivalent load (pounds) % area = tire contact area (in-in) % cbr = California bearing ratio (dimensionless) % % Output arguments % t = pavement thickness function t = thickness(load,area,cbr) t = sqrt(load ./ (8.1 .* cbr) + area/pi);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/16/2011 for the course MECHANICAL 000 taught by Professor R during the Fall '11 term at IUPUI.

### Page1 / 31

matlab_functions - Introduction to MATLAB MATLAB Functions...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online