### Create a StudySoup account

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

Already have a StudySoup account? Login here

# 5 Outline for CMPSC 200 with Professor Quick at PSU

### View Full Document

## 35

## 0

## Popular in Course

## Popular in Department

This 8 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at Pennsylvania State University taught by a professor in Fall. Since its upload, it has received 35 views.

## Similar to Course at Penn State

## Popular in Subject

## Reviews for 5 Outline for CMPSC 200 with Professor Quick at PSU

### 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: 02/06/15

Chapter 2 MATLAB Environment 23 Solving Problems with MATLAB Variables can be any length up to 63 characters can t start with a number no s or other characters try using underscores to separate words in a variable inspacestart end spacing inspace1103 gt 1 55 10 ogspacestarting value of 10quotx end val of 10quotx elements ogspace133 gt 10 100 1000 is used to perform element by element multiplication is used to perform element by element division quot is used to perform element by element exponentiation is used at the end of a variable to transpose it Formats format short 4 decimal digits format long 14 decimal digits format rat fractional form 24 Saving Your Work Dairy allows you to record a MATLAB session savelt filename gt ex save myfunctionfile loadlt filename gt ex load myfunctionfile Chapter 3 Built In MATLAB Functions 33 Elementary Math Functions sqrtx gt takes the square root of variable x remxy gt calculates the remainder of x divided by y sizex gt returns the size of the matrix x sinx cosx tanx etc gt selfexplanatory trig functions asinx acosx atanx etc gt selfexplanatory inverse trig functions expx gt computes the value of equotx ogx gt computes the value of nx og10x gt computes the value of ogx absx gt finds the absolute value factorialx gt computes the factorial ofx floorx or ceilx gt rounds x to the nearest integer factorx gt finds the prime factors of x gcdxy gt finds the greatest common denominator ofx and y same w lcmxy primex gt finds all prime numbers less than x 35 Data Analysis Functions maxx gt finds largest value in a vector or largest in a column in a matrix minx gt finds smallest value in a vector or smallest in a column in a matrix meanx medianx modex gt easy for a vector in a matrix it does it for each row sumx gt adds up all the elements in vectorx or column in a matrix prodx gt computes product of all elements in a vectorx or column of a matrix cumsumx gt creates a vector the same size as x adds up the values ofx as it moves along the vector cumprodx gt same as above except with multiplication sortx gt sorts the elements of a vector x into ascending order sortx ldescend gt sorts the elements of a vector x into descending order sortrowsx gt to only sort the rows of a matrix lengthx gt determines the length of a vector or largest dimension in a matrix stdx gt calculates the standard deviation of x varx gt calculates the variance of the data in x randn gt returns a n x n matrix with numbers between 0 and 1 randmn gt returns a m x n matrix with numbers between 0 and 1 randnn gt returns a n x n matrix with numbers from 1 to 1 randnmn gt returns a m x n matrix with numbers from 1 to 1 complexx y gt returns x yi ex complex35 35i Chapter 4 Manipulating MATLAB Matrices 42 Problems With Two Variables Meshgridxy gt takes two inputs x and y Then will create two two dimensional matrices Each of the resulting matrices has the same number of rows and columns 43 Special Matrices zerosm or zerosmn gt creates a matrix m x m or m x n filled with zeros onesm or onesmn gt creates a matrix m x m or m x n filled with ones diagA gt extracts the diagonal of twodimensional matrix A fliplr gt flips a matrix into its mirror image from right to left flipud gt flips a matrix vertically magicm gt creates matrix m x m all rowscolumns add to same value Chapter 5 Plotting 51 TwoDimensional Plots plotxy gt plots x versus y in a graphics window xlabel Time sec gt titles the x axis ylabel Distance feet gt titles the y axis grid on gt turns on the grid on the plot hold on or off gt allows the user to put more than one plot on a graph plotxy ob gt changes the line to blue dashed and the points to circles or o s axis 23010 gt fixes the axis of the plot of x to 2 to 3 and y to O to 10 legend string1 string2 etc gt adds a legend to the graph 52 Subplots subplotmnp gt divides the graphics window into a grid of m by n p is the subplot 53 Other Types of TwoDimensional Plots polartheta r gt plots a polar graph semilogxxy gtgenerates a plot of values x and y using a logarithmic scale for x only semilogyxy gtgenerates a plot of values x and y using a logarithmic scale for y only loglogxy gtgenerates a plot of values x and y using a logarithmic scale for x and y barx gt generates a vertical bar graph barhx gt generates a horizontal bar graph bar3x gt generates a 3dimensional bar graph bar3hx gt generates a 3dimensional horizontal bar graph piex gt generates a pie chart each element in x is a slice of the pie pie3x gt generates a 3dimensional pie chart histx gt generates a histogram fplot sinx 2pi 2pi gt creates a plot with x versus function from 2pi to 2pi 54 ThreeDimensional Plotting plot3xyz gtcreates a 3dimensional line plot comet3xyz gt animated version of plot3 meshx or meshxyz gt creates a meshed surface plot surfz or surfxyz gt creates a surface plot similar to mesh colormap XXXXX gt color schemes can be atumn spring jet bone a few more Chapter 6 UserDefined Functions 61 Creating Function MFiles user created function files that can be called from another m file if it is located in the MATLAB directory It must contain the word function a variable that defines the output a function name and a variable used for the input argument For example function result myfunctionx function must be saved as myfunction accept 1 input which is stored a x and contains the word function The output is called result At the end of the function make sure to have result to return the result to the main m file 63 Anonymous Functions and Function Handles ex ln x logx the symbol tells MATLAB that In is a function the x is the input to the function Use function handles to make fplot less awkward looking Chapter 7 UserControlled Input and Output 71 UserDefined Input Z input Enter a value will display Enter a value and in the command window the user enters in a value for 2 For a two dimensional matrix you must enter in your value in brackets Strings must be entered inside apostrophes String 72 Output Options disp String is used to display text in the command window fprintf There are f cows in the pasture cows f fixed point format we typically use f You can use g MATLAB chooses fixed point or exponential format s string of characters or d decimal format n will create a new line r carriage return t tab b backspace 73 Graphical Input xy ginput gt allows the user to select a point on the graph stored in x amp y 74 Using Cell Mode in MATLAB MFiles Just simply put at the beginning of where you d like your cell to start 75 Reading and Writing Data From Files Importing doc filename uiimport filenameextension xsread filenamexls Exporting xxwrite filenamexls M M array you wish to store into the spreadsheet Chapter 8 Logical Functions and Control Structures 81 Relational and Logical Operators Relational lt less than lt less than or equal to gt greater than gt greater than or equal to equal to N not equal to Logical amp and N not I or xor exclusive or 83 Logical Functions findvariable gt number this will search variable for a integer gt the number defined ex row col findtempgt986 84 Selection Structures The Simple If if comparison statements end The lfElse Structure if comparison statements else statements end The Elseif Structure if comparison if agelt16 statements disp Sorry you ll have to wait elseif comparison elseif agelt18 statements disp You can have a youth license elseif comparison elseif agelt7O statements disp You can have a regular license else else statements disp Drivers over 70 require end end The Switch and Case switch variable case optionl code to be executed ifvariable is equal to option 1 case option2 code to be executed ifvariable is equal to option 2 otherwise code to be executed ifvariable is not equal to any options end Menu input menu Message to user ltext for buttonl ltext for button2 etc 85 Repetition Structures Loops For Loops for index matrix for k 1 3 7 commands to be executed k end end While Loops k 0 while criterion while klt3 commands to be executed k k1 end end Break this is used to terminate a loop prematurely Continue similar to break it just skips that command and goes to the next pass Chapter 9 Matrix Algebra 91 Matrix operations and Functions dotA B gt finds the dot product of matrix A and matrix B crossAB gt finds the cross product of matrix A and matrix B invA gt gets the inverse of matrix A detA gt get the determinant of matrix A Chapter 10 Other Kinds of Arrays 101 Data Types int8 8bit signed integer uint8 8bit unsigned integer int16 16bit signed integer uint16 16bit unsigned integer int32 32bit signed integer uint32 32bit unsigned integer 103 Character Arrays Q char Holly Steven lMeagan David will sort vertically R 9884738895100 If we try to put these into one array the values for R will correlate with the ASCII numbers for their represented keyboard values If you want numbers to put next to the names you must do 5 nusttrR then simply table QS 104 Cell Arrays Cell arrays can store different data types and sizes Ex mycearray ABC 105 Structure Analysis Multiple arrays of different data types can be stored in structure arrays EX A 13 B abcdefg C single123456 mystrucutresomenumbers A somenumbers 1 2 3 mystructuresomeletters B somenumbers 1 2 3 someetters labcdefgI Chapter 11 Symbolic Mathematics 111 Symbolic Algebra symbolic variable x sym x and y 2x3quot2xquot2 6x 9 If you type in y in the command window it will return the y equation num den numdeny gt this ll extract the numerator and denom from a fraction expandx gt expands the expression factorx gt factors the expression collectx gt collects similar terms slmpllfyx gt simplifies each part of an expression or equation 112 Solving Expressions and Equations soveE gt solves the function E for x assume x is defined as a symbolic variable 114 Calculus Differentiation first define a function dist sym 2020slnplt1020 Then use the diff function velocity diffdist If you re told to find the nth derivative use difffunctlon n Integration define a function y sym xA3 slnx use int command inty gt 025x cosx To evaluate from IXV subsderiv y su bsderiv x EASIER APPROACH just do intfunction upper value lower value Chapter 12 Numerical Techniques 121 Interpolation Linear most common way to estimate points between two points straight line ex x 05 y 15 10 9 6 2 O lnterp1xy35 gt ans 4 Cubic Spline smoother curve between points ex lnterp1xy35 lspline 122 Curve Fitting Linear Regression simplest way to model a data set with a straight line ex x 05 y 15 10 9 6 2 O polyfltxy1 gt two values for yaxb Polynomial Regression same as above except 1 becomes a number 2 or greater Polyval Function only takes two inputs the coefficients from polyfit and xvalues for which we would like to calculate new values Ex polyvalpolyfltxy4 smoothx 0R coeff polyfltxy4 polyvalcoeff smoothx 123 Using the Interactive Fitting Tools To activate curvefitting tools generate a plot and then select Tools gt Basic Fitting From there you can select what type of fitting you would like linear cubic and show equations You can also type in cftool to bring up the curvefitting toolbox 124 Differences And Numerical Differentiation If all you have is your data and no equations relating it use this method AVAX lle39Ylllxz39xlll to get Ax deltax diffx to get Ay deltay diffy slope deltaydeltax 125 Numerical Integration This isn t the int function as used in Chapter 11 we are finding a bunch of rectangular areas under the curve and adding them together To do this you must do the following xOO11 yxquot2 avgy y110diffy2 sumdiffxavgy gt ans 03350 Simpson Quadrature MATLAB uses this quad func lower bound upper bound Lobatto Quadrature MATLAB uses this quadl func lower bound upper bound 126 Solving Differential Equations Numerically myfun ty 2t corresponds to dydt 2t ty ode45myfun 11 1 By graphing the answer corresponds to tquot2 Chapter 13 Advanced Graphics 131 Images advanced graphics are handled with image and imagesc functions surfpeaks gt 3D surface plot of the peaks function peaks is just in MATLAB pcolorpeaks gt 2D surface plot of the peaks function shading flat gt makes the grid lines disappear colormapbone gt makes the image look like an xray colormapjet gt the default coloring for an image imfinfo imagejpg gt returns a whole bunch of info about the image colormapmap gt made the mandrill image from grey to colors axis image gt corrects the axis settings so the image isn t warped How to load an image and get a X value make sure the image is in the MATLAB dir X imread imagenamejpg loads the image imageX displays the image in a plot axis image fixes axes so image isn t warped axis off turns off axis so the image is the only thing displayed 132 Handle Graphics Plot Handles assigning a plot name known as handle allows us to easily ask MATLAB to list the plotted object s properties Ex x 110 y x15 h plotxy Variable h is the handle for the plot To get the properties simply do gethandlename Figure Handles fhande figure1 getfhandle The only thing that differentiates figure handles and plot handles is the color property If we don t specify a function handle we can just do getgfc What We Use Handles For to change colors and namestitles setlmagehandle lcolor red 0R setlmagehandle name Tltle 133 Animation There are two techniques to creating animations 1 Redrawing and erasing 2 Creating a movie Redrawing and Erasing In order to do this option you need to first create a plot then adjust the properties of the graph each time through a loop EX x10O110 k 1 y kxquot22 h plotxy grid on axls 1010100100 Specifles the axis while klt1 Start a loop k k001 lncrement k y kxquot22 Recalculate y seth lXData x lYData y Reassigns the x and y values used in the graph drawnow Redraws the graph now doesn t wait until program is done end Movies Movies are used typically for surface plots it ll run through the computation stuff once might be a little jerky due to computations then play through the whole set of frames twice Transparency Set by the function alphadecimal 0 to 1

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

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

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

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

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

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

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.