×

### Let's log you in.

or

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

×

or

## Week 2 Programming Notes

by: Neha Bhagirath

12

0

13

# Week 2 Programming Notes BE1500

Neha Bhagirath
WSU

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

×
Unlock Preview

We are using MATLAB, and these are from Prof Whitehead's class
COURSE
Intro to Programming
PROF.
TYPE
Class Notes
PAGES
13
WORDS
KARMA
25 ?

## 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.

×

## Reviews for Week 2 Programming Notes

×

×

### 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: 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

×

×

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

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

#### 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