Lecture_07_horowitz - 1 E7: INTRODUCTION TO COMPUTER E7:...

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

View Full Document Right Arrow Icon
E7 L6 1 E7: INTRODUCTION TO COMPUTER E7: INTRODUCTION TO COMPUTER PROGRAMMING FOR SCIENTISTS AND PROGRAMMING FOR SCIENTISTS AND ENGINEERS ENGINEERS Lecture Outline (pages 139-163 in E7 text) 1. Functions revisited 2. Local vs global variables, evalin 3. Function that act on functions through function handles Copyright 2007, Horowitz, Packard. This work is licensed under the Creative Commons Attribution-Share Alike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
Background image of page 1

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

View Full DocumentRight Arrow Icon
E7 L6 2 E7 Midterm 1 – FRIDAY 9/28 E7 Midterm 1 – FRIDAY 9/28 Exam hours: Discussion Section 105: 12:10-1:00 Discussion Section 110: 1:10-2:00 Exam is closed- book (~50 minutes) 1 sheet (front and back) of HANDWRITTEN notes is allowed Students must enter through first-floor (top) door. Arrive early and form a line. Student ID will be required to take the exam Students must remain seated until exam has ended. Students must exit through bottom (ground) doors.
Background image of page 2
E7 L6 3 FUNCTIONS in Matlab FUNCTIONS in Matlab A set of commands that execute a “task” that can be reuse in several instances. Function files must always possess the extension .m The file name should be the same as the function’s Functions can call other functions! Variables in a function file are local Not recognized in Matlab’s command window or in any other function Not stored in the Matlab workspace.
Background image of page 3

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

View Full DocumentRight Arrow Icon
E7 L6 4 Finding appropriate Functions with lookfor Use lookfor from the matlab command window to get functions that are relevant to your task Example: >> lookfor imaginary I Imaginary unit. J Imaginary unit. COMPLEX Construct complex result from real and imaginary parts. IMAG Complex imaginary part.
Background image of page 4
E7 L6 5 Example of a function Example of a function Calculate and plot the ( x - y ) trajectory of a projectile given: It’s initial speed: The angle of departure Equations used (physics):
Background image of page 5

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

View Full DocumentRight Arrow Icon
E7 L6 6 Function Function cannon1 function   [t, x, y] = cannon1(v0,theta,g) % cannon computes the trajectory of a projectile fired at  an angle theta % with initial velocity v0 under gravitational  acceleration g % Outputs: t: time vector, x: - x-coordinate vector, y: y- coordinate vector   % Compute flying time of the projectile tmax = 2*v0*sin(theta)/g; % Define time vector of length 100 t = linspace(0,tmax,100); % Compute x-coordinate vector x = v0*cos(theta) .* t;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/17/2011 for the course ENGINEERIN 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 34

Lecture_07_horowitz - 1 E7: INTRODUCTION TO COMPUTER E7:...

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

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