Matlab_functions

Matlab_functions - Introduction to MATLAB MATLAB Functions...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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)
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online