




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Georgia Southern University Mechanical and Electrical Engineering Technology
Spring 2009
Prof. AlbaโFlores
sqrt(x) โ Square root function exp(x)p( ) โ Exponentialp function log(x) โ Natural Logarithm log10(x) โ Common logarithm cos(x) โ Cosine function sin(x) โ Sine function tan(x) โ Tangent function acos(x) ( ) โ Inverse cosine ffunction asin(x) โ Inverse sine function atan(x) โ Inverse tangent function
Function calls
function [Output Variable List] = function name (Input Variable list) endend Description
function [out1, out2, ...] = funname (in1, in2, ...) defines function funname that accepts inputs in1, in2, etc. and returns outputs out1, out2, etc. All functions should end with the instruction end
You add new functions to the MATLAB vocabulary by expressing themYou add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file ( Mโfile) funname.m
function factorial = fac(n) ffactorial t i l = 11 ; for i = 1 : n factorial = factorial * i; end end
Function name: fac Output variable: factorial Input variable: n
We can create a Matlab file called stat.m that defines a new function called stat that calculates the mean and standard t d d d d eviationi ti off a vector.t
function [mean, stdev] = stat(x) n = length(x); mean = sum(x)/n; stdev = sqrt(sum(( x โ mean).^2/n)); end
Function name: stat Output variables: mean, stdev Input variable: x