Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:

Similar presentations


Presentation on theme: "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:"— Presentation transcript:

1 March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3: Exercise 5.1 FunctionsFunctions

2 March 2005 2R. Smith - University of St Thomas - Minnesota Data Independence How do we ‘really’ solve a problem?How do we ‘really’ solve a problem? 1. Figure out a specific answer to a specific situation1. Figure out a specific answer to a specific situation 2. Figure out a general solution that applies to the broadest range of data –2. Figure out a general solution that applies to the broadest range of data – A “Data Independent” solution

3 March 2005 3R. Smith - University of St Thomas - Minnesota Matlab #3 Exercise 5.1, p. 108Exercise 5.1, p. 108 It’s possible to solve it for a specific matrixIt’s possible to solve it for a specific matrix “Doing it right” means it works for any matrix of coins“Doing it right” means it works for any matrix of coins –Assume the coin values remain constant –Do we need a separate calculation of each denomination? “Looping” through matrix values“Looping” through matrix values –It has to be 1 matrix + 1 scalar, or 2 matching matrices

4 March 2005 4R. Smith - University of St Thomas - Minnesota Functions Live in.m files with a matching nameLive in.m files with a matching name Options for the function declarationOptions for the function declaration –Return no value: function f (arg1, arg2…) –Return a value: x = function f (arg1, arg2…) –Return multiple values: [a1, a2] = function f (arg1, …) Comments follow the declarationComments follow the declaration –How to use the function – typed out for ‘help ’ Lines of computationLines of computation –Results assigned to return value variables, if any –All statement lines end with semicolons

5 March 2005 5R. Smith - University of St Thomas - Minnesota Debugging Try out some functionsTry out some functions –Hypotenuse –Twomeans – arith and geom If you get an error in function definitionIf you get an error in function definition –If you function is called ‘fun’, give this command –clear fun –Then modify the function and try it again

6 March 2005 6R. Smith - University of St Thomas - Minnesota In-line functions Functions without filesFunctions without files F = inline(‘calculations here’, ‘var1, ‘var2’..)F = inline(‘calculations here’, ‘var1, ‘var2’..) Invoke with F(var1, var2..)Invoke with F(var1, var2..)

7 March 2005 7R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by- sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:"

Similar presentations


Ads by Google