Matlab_functions

# Matlab_functions - Introduction to MATLAB MATLAB Functions...

This preview shows pages 1–9. 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 2006

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 specific 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 files in MATLAB are equivalent to subroutines in FORTRAN, functions in C, and procedures in Pascal Function files constitute the basis for complex programs and model prototyping Functions can be profiled (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 file name (except for the .m termination) containing the function script - A function called atmosphere should reside inside an M- file 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 files can incorporate two types of variables: - Local - Global Local variables exist inside the function that uses them. All variables defined inside a function are local unless otherwise defined Global variables are shared among various functions and are defined as such in all function files where they are expected to be used - global x y z - This statement defines 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 ( ) ------------------------ A ! --- + = t P A

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/01/2012 for the course CEE 3804 taught by Professor Aatrani during the Spring '07 term at Virginia Tech.

### Page1 / 31

Matlab_functions - Introduction to MATLAB MATLAB Functions...

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

View Full Document
Ask a homework question - tutors are online