×

### Let's log you in.

or

Don't have a StudySoup account? Create one here!

×

or

by: Ana Beyer

33

0

6

# Engr 101 - Week 3 - Lecture 4 Engr 101

Marketplace > University of Michigan > Engineering > Engr 101 > Engr 101 Week 3 Lecture 4
Ana Beyer
UM

Get a free preview of these Notes, just enter your email below.

×
Unlock Preview

These notes cover what functions are, how they're used, and how you can create your own.
COURSE
Introduction to Computer Programming
PROF.
Laura Alford
TYPE
Class Notes
PAGES
6
WORDS
CONCEPTS
Engr101, functions, CreatingFunctions, Matlab
KARMA
25 ?

## Popular in Engineering

This 6 page Class Notes was uploaded by Ana Beyer on Wednesday September 21, 2016. The Class Notes belongs to Engr 101 at University of Michigan taught by Laura Alford in Fall 2016. Since its upload, it has received 33 views. For similar materials see Introduction to Computer Programming in Engineering at University of Michigan.

×

## Reviews for Engr 101 - Week 3 - Lecture 4

×

×

### What is Karma?

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/21/16
Lecture 4 - Creating Functions Wednesday, September 21, 205:59 PM What is a function? • A function is anabstraction over a chunk of computation • In other words… ○ Data goes in it gets processed new data comes out! • It's an abstraction because we can use it w/o worrying about how the computation works internally • Every function has 2 major parts: ○ Interface& implementation For an example, refer to ESP.m file in Lecture Scripts folder For an example, refer to ESP.m file in Lecture Scripts folder Creating a New Function Write variables in their own .m file function [ x ] = createFunction( a , b, c) % createFunction is used to …. % x = (a + b) .* c computes the equation based on the values given to the variables a, b, and c x = (a + b) .* c; end Variable Scope • Variables within a function are COMPLETELY DIFFERENT than those in the main program - even if they have the same name! • Global scope- within the scope of your main program • Local scope - within the scope of the function alone Name doesn't matter between scopes BUT order matters! For an example, refer to ESP.m file in Lecture Scripts folder Creating a New Function Write variables in their own .m file function [ x ] = createFunction( a , b, c) % createFunction is used to …. % x = (a + b) .* c computes the equation based on the values given to the variables a, b, and c x = (a + b) .* c; end Variable Scope • Variables within a function are COMPLETELY DIFFERENT than those in the main program - even if they have the same name! • Global scope- within the scope of your main program • Local scope - within the scope of the function alone Name doesn't matter between scopes BUT order matters! For an example, refer to ESP.m file in Lecture Scripts folder Creating a New Function Write variables in their own .m file function [ x ] = createFunction( a , b, c) % createFunction is used to …. % x = (a + b) .* c computes the equation based on the values given to the variables a, b, and c x = (a + b) .* c; end Variable Scope • Variables within a function are COMPLETELY DIFFERENT than those in the main program - even if they have the same name! • Global scope- within the scope of your main program • Local scope - within the scope of the function alone Name doesn't matter between scopes BUT order matters! General Guidelines • Use meaningful names for the parameters and return variables so that you can easily recognize them at a later time • Indent the body of the function to make it easier to read and to keep everything organized • Don't forget comments within the function explaining what it does/how it works for futurereference General Guidelines • Use meaningful names for the parameters and return variables so that you can easily recognize them at a later time • Indent the body of the function to make it easier to read and to keep everything organized • Don't forget comments within the function explaining what it does/how it works for futurereference

×

×

### BOOM! Enjoy Your Free Notes!

×

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

Bentley McCaw University of Florida

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Jennifer McGill UCSF Med School

#### "Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over \$500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

Jim McGreen Ohio University

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Parker Thompson 500 Startups

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!
×

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com