MATLAB Week1 Lecture3 Web
MATLAB Week1 Lecture3 Web
Jon M. Ernstberger
January 6, 2008
MATLAB Scripts
What is a Script?
A MATLAB script is a sequence of commands that has been saved
to a file.
Exercises
Exercises, cont.
MATLAB Functions
F (x) : Rn → Rm ?
ex: f (x, y ) = x 2 + y 2 , x 2 − y 2
The idea is “ For one (set of) input(s), there is one (set of)
output(s).”
We often want to define MATLAB “functions” which take
inputs and return non-ambiguous outputs.
Multi-input/output functions
function [f,g]=pseudo_fcn1(x,y)
f=x^2+y^2;
g=x^2-y^2;
A Sample Function
area=pi*r^2;
In-Class Exercise
Download circle properties.m and change this function to also
output circumference.
Jon M. Ernstberger MATLAB for the Sciences
The MATLAB Editor
Scripts and Functions
The MATLAB Editor, Cont.
Assignments
References
More Exercises
Comments
What’s the big deal about comments?
Example
% Jon Ernstberger
% 12/22/2008
% Sample Comments
MATLAB Profiler
Useful for identifying trouble points in your code.
Programming Hint
Use “Left/Right Split Screen” in order to edit scripts and
functions. This helps the programmer see the most code possible.
In-Class Assignments
References
S.L. Edgar.
Fortran for the’90s: problem solving for scientists and
engineers.
Computer Science Press New York, NY, 1992.