New User Special Price Expires in

Let's log you in.

Sign in with Facebook


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


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Week 2 Programming Notes

by: Neha Bhagirath

Week 2 Programming Notes BE1500

Neha Bhagirath

Preview These Notes for FREE

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

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

We are using MATLAB, and these are from Prof Whitehead's class
Intro to Programming
Tonya Whitehead
Class Notes
25 ?




Popular in Intro to Programming

Popular in Engineering and Tech

This 13 page Class Notes was uploaded by Neha Bhagirath on Sunday May 22, 2016. The Class Notes belongs to BE1500 at Wayne State University taught by Tonya Whitehead in Spring 2016. Since its upload, it has received 12 views. For similar materials see Intro to Programming in Engineering and Tech at Wayne State University.

Similar to BE1500 at WSU

Popular in Engineering and Tech


Reviews for Week 2 Programming Notes


Report this Material


What is Karma?


Karma is the currency of StudySoup.

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

Date Created: 05/22/16
Anonymous Functions and Plotting  ­Syntax is “plot( x, y)”  ex . X=1:10  Y=01:0:1.1  ­when you are graphing make sure you use the same number of x and y coordinates                           ­Multiple Plotting on the same graph:      Ex. plot(X,Y,'r­­o')    Adding Titles and Axis Labels  ­title(‘string’)  ­xlabel(‘string’)  ­ylabel(‘string’)  ­legend(‘string’)  ­­­ ex. legend(‘Function 1’, ‘Function 2’)  ­if you have 3 data sets put 3 strings in there, separated by commas   ­if you put y1=x^2, and x=1:10, it will do matrix multiplication so do y=x.^2 instead       ­how to do put your legend in the best place ­­­> legend('Data Set 1','Data Set  2','Location','Best') but don’t close the window for the plot or it won’t graph   Hold on/hold off: hold on means that you plot the figure in there, then put hold off. THEN graph  another graph and it’ll be in another window   ­putting points by hand: use square brackets            Homework:    Answer:    ­and put hold off after it     ­you can choose where to put the legend: legend('Data Set 1','Location','Best') ­­­> instead of  best, put n,s,e,w for north south east west      ­if you want to make the same scale to compare:    Subplot: multiple graphs in the same figure ex. subplot(2,1,1) means 2 rows, 1 column, and  position 1     Homework: Answer:          Anonymous Functions: single line equations      Ex.   f =         @(x)x.^(1/3)    >> f(8)    ans =         2                ­the (a,2,2) means that a is from 0­10 and b and c equal 2 always   And its @a because we use a for our variable     Homework:      Answer:  a)    >> Test1=@(x)(cos(x).^(5/2))*(x­4).^2­x.^(1/3)    Test1 =         @(x)(cos(x).^(5/2))*(x­4).^2­x.^(1/3)    >> fplot(@(x) Test1(x),[0,pi/2])    b)    ­when you have 2 vectors, use plot function   Answer:            Day 4  ­The simplest type of MATLAB program is called a script, has a .m extension. You can run a  script by typing its name at the command line  ­Anonymous Functions: not stored in a program file, but is associated with a variable whose  data type is function_handle. Can contain only a single executable statement.        Practice:        >> R=[0, pi/8, pi/6, pi/4, pi/2]    R =             0    0.3927    0.5236    0.7854    1.5708        >> function_name=@(x)(sin(x)).^2+((cos(x)).^2./(sin(x)­cos(x)))  % DOT BEFORE DIVISION    function_name =         @(x)(sin(x)).^2+((cos(x)).^2./(sin(x)­cos(x)))    >>  B=function_name(R)    B =       1.0e+15 *       ­0.0000   ­0.0000   ­0.0000   ­4.5036    0.0000    New question:    Answer:  >> A=1:10    A =         1     2     3     4     5     6     7     8     9    10     >> f=@(x)3*x.^2+5    f =         @(x)3*x.^2+5    >> f(A)    ans =         8    17    32    53    80   113   152   197   248   305    >> Y=f(A)    Y =         8    17    32    53    80   113   152   197   248   305    >> subplot(3,1,1)  >>  plot(A,Y)  >> f=@(x)12*x­(5*x.^2)    f =         @(x)12*x­(5*x.^2)    >> f(A)    ans =         7     4    ­9   ­32   ­65  ­108  ­161  ­224  ­297  ­380    >> Y2=f(A)    Y2 =         7     4    ­9   ­32   ­65  ­108  ­161  ­224  ­297  ­380    >> plot(A,Y2)  >> subplot(3,1,1)  >>   >> plot(A,Y)  >> subplot(3,1,2)  >> plot(A,Y2)  >> f=@(x)x.^3+(2*x.^2)­(3/(x­x.^2))    f =         @(x)x.^3+(2*x.^2)­(3/(x­x.^2))    >> f(A)    f =         @(x)x.^3+(2*x.^2)­(3./(x­x.^2))    >> f(A)    ans =       1.0e+03 *          ­Inf    0.0175    0.0455    0.0963    0.1752    0.2881    0.4411    0.6401    0.8910    1.2000    >> Y3=f(A)    Y3 =       1.0e+03 *          ­Inf    0.0175    0.0455    0.0963    0.1752    0.2881    0.4411    0.6401    0.8910    1.2000    >> subplot(3,1,3)  >> plot(A,Y3)    ­plot has to have a vector, and fplot can have a vector or a function      ­you can also use fplot for functions with multiple variables, however you have to put individual  values in for all but 1 variable  Ex. f=@(a,b,c)a.^2+b.^2+c.^2           


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

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!"

Anthony Lee UC Santa Barbara

"I bought an awesome study guide, which helped me get an A in my Math 34B class this quarter!"

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

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


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


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:

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

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.