Ch3 Programming with MATLAB - Spring 2011

Ch3 Programming with MATLAB - Spring 2011 - PGE 310:...

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

View Full Document Right Arrow Icon
MATLAB Programming Chapter 3 of Numerical Methods with MATLAB, Gerald Recktenwald PGE 310: Formulation and Solution in Geosystems Engineering Dr. Balhoff Spring 2011 1 Review of Plotting in MATLAB •M a t l a b h a s s o m e r e a l l y p o w e r f u l g r a p h i c s •2 D p l o t s c a n b e m a d e e a s i l y i n M A T L A B –p l o t ( x , y ) –A n n o t a t i n g h e l p s m a k e a p r o f e s s i o n a l p l o t –s u b p l o t ( x , y , t h i s p l o t ) c o m m a n d a l l o w s f o r m u l t i p l e p l o t s –L o g p l o t s a l s o c o m m o n •3 D p l o t s ( s u r f a c e a n d c o n t o u r ) a r e a l s o u s e f u l u r f ( x , y , Z ) - o r s u r f c , surfl, mesh- uses vectors u r f ( X , Y , Z ) u s e s m a t r i c e s f o r X a n d Y –c o n t o u r ( X , Y , Z ) –‘ m e s h g r i d ( x , y ) c o n v e r t s v e c t o r d a t a o f x , y t o m a t r i c e s 0 100 200 300 400 500 600 700 800 900 10 1 10 2 10 3 Semilog Plot 0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Linear Plot -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 0 2 -0.5 0 0.5 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
Today…We learn some real programming! •S c r i p t f i l e s a n d f u n c t i o n - f i l e s –T w o t y p e s o f . m f i l e s –C o d e w r i t t e n i n M A T L A B •f u n c t i o n f i l e s r e q u i r e inputs and send back outputs –W e h a v e a l r e a d y b e e n u s i n g f u n c t i o n s ! –A n y n u m b e r o f i n p u t s a n d o u t p u t s a l l o w e d •I n p u t a n d O u t p u t ( 1 / O ) –i n p u t –d i s p –f p r i n t f 3 Scripts: Sequences of Interactive Statements Stored in a File •H o w a r e t h e y u s e d ? l o t l i k e w h a t w e h a v e b e e n d o i n g i n t h e c o m m a n d w i n d o w ( b u t n o w w e c a n save our work and make changes later) –H a v e n o i n p u t o r o u t p u t p a r a m e t e r s ( w h i c h we will find different than a function file) i d e E f f e c t s a n d C o m m e n t s l l v a r i a b l e s a r e a d d e d t o t h e w o r k s p a c e ( i . e . , c o m m a n d w i n d o w ) –O l d v a r i a b l e s i n w o r k s p a c e w i l l b e r e p l a c e d b y t h o s e o f s a m e n a m e –R e m e m b e r y o u c a n i n c l u d e c o m m e n t s b y p r e c e d i n g t h e m w i t h a % 4
Background image of page 2
Opening an ‘.m’ file •H o w t o o p e n : F i l e m e n u o r w h i t e s h e e t OR 5 An Example of a Script ‘.m’ file 6
Background image of page 3

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

View Full DocumentRight Arrow Icon
Function m-Files: Code that communicates with the command window and other functions script via predefined list of input and output parameters •S i m i l a r t o s u b r o u t i n e s i n o t h e r l a n g u a g e s •f u n c t i o n [ outputParameterList ] = functionName( inputParameterList ) List of outputs (separated by commas) List of inputs (separated by commas) •F irs t word is always function •Ou tpu t l t op t iona l and inc luded in square bracke ts •func t ionName must also be the same as the file name !
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/06/2011 for the course PGE 310 taught by Professor Klaus during the Spring '06 term at University of Texas at Austin.

Page1 / 19

Ch3 Programming with MATLAB - Spring 2011 - PGE 310:...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online