### Create a StudySoup account

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

Already have a StudySoup account? Login here

# ComputationLaboratoryIII CS123

Drexel

GPA 3.88

### View Full Document

## 27

## 0

## Popular in Course

## Popular in ComputerScienence

This 13 page Class Notes was uploaded by Vito Kilback on Wednesday September 23, 2015. The Class Notes belongs to CS123 at Drexel University taught by Staff in Fall. Since its upload, it has received 27 views. For similar materials see /class/212456/cs123-drexel-university in ComputerScienence at Drexel University.

## Popular in ComputerScienence

## Reviews for ComputationLaboratoryIII

### 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: 09/23/15

17 Chapter 18 More about plotting W Section 181 Parametric plotting In the two dimensional plotting we have done so far the expression given as the first argument to plot typically involves a variable which is mentioned again in the second argument eg plot tquot21 t02 The plot uses the value of the plot variable t in the example as the first coordinate horizontal or quotxquot axis while the value of the expression specifies the second coordinate of the graph vertical or quotyquot axis Given the plot expression and the range of the plotting variable we can easily infer that points such as 01 or 5 5quot21125 will be on the graph In other words the set of points t1 t2 tE 01 will be used as the basis for drawing the plot The kind of plotting we have done so far is good at drawing curves where the second coordinate is a function of the plot variable and the first coordinate is just the value of the plot variable There is another form of plotting where the first and second coordinates are both expressions of the plot variables This is called parametric plotting plot will do a parametric plot if its first argument is a list of three items The first item is an expression for thex horizontal axis coordinate the second item is an expression for the y vertical axies coordinate and the third item is a variable with an associated range The x and y expressions should involve this variable gure 1811 Format of plot used for parametric plotting pl ot X expr ess 739 on y x expression and y expression should evaluate expression va r p 70 1 range to numerical values when varhas a numerical value Values from the plot range are selected for var A curve described by the x expression y expression coordinates as var varies over the plot range is drawn Example 1811 Parametric plotting 1104 COS I 2511 I t 0 quot2 7 scaling The set of points that will be plotted will be constrained drawn from the set of points cost 2sint tE 0239TE eg points such as cosO 2sin0 10 cos1 2 sin1 plot cost 2sint t02 75 09950041653 01996668333 cosrc 2 sinTc 1 0 etc The scaling is constrained so that the X axis is drawn to the same scale as the y axis Otherwise the plot will be drawn so that the vertical and horizontal ranges take up the same space This is the same curve but the default scaling unconstrained is used The default makes the vertical and horizontal ranges take up the same space but that magnifies the horizontal scale by a factor of two This curve has points on it such as cos0 sin0 1 0 cos1 1 sin1 1 009950041653 0009983341665 cosrc 7c sinTc 75 TE 0 etc This curve can39t be drawn using the other style of plotting because the curve does not depict a function of t since there are several points on it for values of t such as tIO or t0 Because the horizontal and vertical ranges are the same the axes are drawn using the same scaling even though the default scaling is in effect If we said scalingconstrained in the plot command we would see the same thing for this plot V Section 182 Plotting with Maple procedures gure 1821 Plotting with Maple procedures Procedures that work with symbolic inputs and return symbolic or numeric results should be okay to plot Procedures that fail with symbolic inputs but work with numeric inputs need to be quoted eg plot39fx39x01 We have seen how to use plot to draw the graphs of various kinds of functions such as sin cos exp etc We have learned how to define our own Maple procedures with gt and with procend proc It is tempting and natural to want to plot such procedures as well However there are complications due to the way that Maple evaluates expressions If If the procedure returns a symbolic expression as a result then plot will work with it However if the procedure needs numeric values for arguments then trying to plot with the procedure will produce an error Example 1821 Procedures that need numeric inputs don39t work with plot plotsinx x 0 1 This is the plotting we are used to 08 07 06 05 04 03 02 01 0b 02 0 d8 i x G 0 sinx sinx 121 x gt 2 l x f x92 can Evaluating sinx returns an expression The f y f 1 plot command we have plots that expression 1 2 y 12 123 We define a simple function plotfxx12 g procm local val val intsinxx1t return val 2 end proct local val 124 val z intsinx x 1t return 2 val end proc gm 8H 2 cos1 2 cost 09094037188 125 P10tftgtt12 1 12 14 16 18 2 h 1 proct local val val intcosxx1 1 if t gt 5 then return val Giving f a symbolic or numeric argument returns a result We demonstrate this by creating a sequence with where each kind of argument is used Plot works with the function we defined Maple evaluates fx gets 2 UK and hands this to plot to work with This defines a function too This function succeeds at returning a result regardless of whether a symbol or a number is given to it Of course if you give it a symbol you get a symbolic expression as a result Maple evaluates the set ftgt and gets 2 1t and 2cos1 2cost before plot starts to operate It is that set of expressions that plot gets to operate on else return val endif endproc pr0ct local val valintcosxx1t if 5 lt t then return val else return val end if end proc h5 03620454462 hz 1 Error in h cannot determine if this expression is true or false 0 lt 2 4 plothtt01 Error in h cannot determine if this expression is true or false 5 lt t 126 127 This is a procedure that has an if statement in it If statements as opposed to piecewise expressions need to be able to decide whether their conditions are true or false whenever they are evaluated This procedure has only one condition tgt5 The evaluation of h5 works When it executes the if statement39s condition is quotif 5lt 5 quot which is false Thus h returns va1 The function does not work when it is given a symbolic input fort When hz is evaluated t gets the symbolic value z1 The if statement can39t determine quotif 5 lt z1quot because z has no known value This is the reason why trying to plot h fails Before plot starts to operate ht is evaluated thas no value because plot hasn39t started to operate yet The evaluation of ht fails making the plot attempt fail There are two simple things to remember that will help you to deal with the situation 1 Maple always evaluates the arguments to a function before it starts doing the function Thus if you do plot gt1 t then g must work with the symbolic input t I It should return an expression that plot can work on not give an error complaining about if statements or whiles that can39t operate properly 2 If you have a properly defined procedure that only works with numeric input then you should quote the procedure invocation plot 39gt139 t This will delay evaluation until after plot starts working and has assigned t a numeric value Quotation should be used sparingly only in situations where it is needed Too much quotation may cause other problems Example 1822 Quotation allows plotting of a procedure that always needs numbers to work plot hz 1 z 1 quot7 Withh defined as in the previous example plot doesn39t work because the evaluation of hz1 Error in h cam determine fails with its if statement if this expression is true or false 0 lt 24 I I By quoting the expression evaluation is h P10 M1 1 Z 1 quot7 zI is delayed until after plot starts to work At that point zhas a numeric value so h39s if 1 statement will work 1 0 2 3 7 0 l l Section 183 Animation with plotsanimate plotsanimate was first discussed in Section 67 animate requires at least three arguments 1 The first argument to animate is the name of a plotting function it could be a procedure you define that returns a plot structure 2 The second argument is a list of arguments to be given to the plotting function 3 The third argument is a variable mentioned in the plot whose value varies from frame to frame of the mov1e 4 Other arguments are optional and can include equations of the form frames number of frames the movie should have background a plot structure that should be drawn in every frame as quotbackgroundquot to the other things being drawn This is also the place to put other options such as labels axes style etc Example 1831 Other ways of producing animations Example Commentary with plots animate ariimate3d animatecurve arrow changecoords complexplot 131 complexplotSd conformal conforn1al3d contourplot contourplotSd coordplot coordplotSd densityplot display dualaxisplot eldplot eldplotSd gradplot gradplotSd graphplotSd implicitplot implicitplotSd inequal interactive interactiveparams intersectplot listcoritplot listcoritplotSd listdensityplot listplot listplot3d loglogplot logplot matrixplot multiple odeplot pareto plotcompare pointplot pointplotSd polarplot polygonplot polygonplotSd polyhedrasupported polyhedraplot rootlocus semilogplot setcolors setoptioris setoptioris3d spacecurve sparsenmtrixplot surfdata textplot textplotSd tubeplot ariimateplot sinAx x 0 10 A 0 2 As with display we can use with to load all the functions in the plot package in expectation of using several The first parameter to an i mate is the name of a plotting function The second parameter is a list of arguments to be giving to that plotting function The expression to be plotted has an extra parameter in this case A that controls how things change from frame to frame Thus the first frame will be pl 0t 51 n 0 X XO 10 The second frame will be pl otS i n 083333X X 0 10 the next frame pl otS i n 16667X XO 10 etc A increments in steps of 225 are being used because the range is from 02 and we are using the default number of frames which is 25 Animate labels each frame with the value of A being used onimotepointplot x x2 2 x color 2 red x 0 2fromes 50 x 0 09 06 04 02 00 05 1 15 2 net 1 pointplot l8 0 21 0 color 2 green symbolsize 40 PLOT 132 onimotepointplot x x2 2 x color 2 red x 0 2fromes 50 background 2 net labels 2 quotdistancequot quotheightquot This is another example of animate The first frame is the plot produced by p0 i ntpl 0t 0 OA22 0 col or r ed The second frame is pointplot110 110quot22 110 etc The number of frames in the movie is specified as an additional argument We create a non animated plot structure that depicts a net that stretches from 180 to 21 0 An additional argument to animate is an equation background p where p is a plot structure It is drawn in every frame of the animation as quotbackgroundquot If we make net the background in our animation we will see the ying point land in the quotnetquot 09 06 height 0 4 02 0 C 0 05 l l 5 2 distance V Section 184 For the curious Why is animate invoked in the way that it is animutdplot sinAx x 0 10 A 0 2 computes several plots using pl 0t 51 n A X XO 10 A distinct value of A in the range 02 is used for each plot which constitutes a frame of the movie We might think we should be able to say this directly with animteplotsinAx x 0 10 A 0 2 However Maple39s quotevaluate all arguments to functions before invoking themquot rule gets the in way here While sinAx will work even if A doesn39t yet have a value plot will not be able to graph sinAx even though it knows how to give x values plot doesn39t know about any values for A so it would fail before animate was ever invoked Thus expecting plotsinAxx010 as one of the arguments to animate isn39t going to work animutd plot sinAx x 0 10 A 0 2 can work because the only evaluation that of sin Ax that occurs before animate gets its arguments will succeed even with A and x having no numeric values Then animate gets to work and supply a values for A and then invoke plotsin Ax x010 The dilemma that language designers have is to balance consistency quotevaluation of functions always works the same wayquot with convenience in particular circumstances by introducing exceptions quotmake it easier for users to remember how to start up animatequot Introducing exceptions may slow down the execution of programs because more checking needs to be done at each point to determine whether the exceptional circumstances hold or not The decisions made rarely satisfy everyone Section 18Z Chapter summary Example 1811 Parametric plotting plot cost 2sint t 0 2 TE scaling constrained plot cost 2sint t02 75 The set of points that will be plotted will be drawn from the set of points cost 2sint tE 0239TE eg points such as cos0 2sin0 10 cos1 2 sin1 09950041653 01996668333 cosrc 2 sinrt 1 0 etc The scaling is constrained so that the X axis is drawn to the same scale as the y axis Otherwise the plot will be drawn so that the vertical and horizontal ranges take up the same space This is the same curve but the default scaling unconstrained is used The default makes the vertical and horizontal ranges take up the same space but that magnifies the horizontal scale by a factor of two plot cost t sint t t0107l This curve has points on it such as cos0 sin0 1 0 cos1 1 sin1 1 009950041653 0009983341665 cosrc 7c sinrt 75 TE 0 etc This curve can39t be drawn using the other style of plotting because the curve does not depict a function of t since there are several points on it for values of t such as t0 or t0 Because the horizontal and vertical ranges are the same the axes are drawn using the same scaling even though the default scaling is in effect If we said scalingconstrained in the plot command we would see the same thing for this plot gure 1821 Plotting with Maple procedures Procedures that work with symbolic inputs and return symbolic or numeric results should be okay to plot Procedures that fail with symbolic inputs but work with numeric inputs need to be quoted eg plot39fx39x01 Example 1831 Other ways of producing animations Example Commentary with plots animate animate3d animatecurve 151 arrow changecoords complexplot complexplotSd conformal conforn1a13d contourplot contourplotSd coordplot coordplotSd densityplot display dualaxisplot eldplot eldplotSd gradplot gradplotSd graphplotSd implicitplot implicitplotSd inequal interactive interactiveparams intersectplot listcontplot listcontplotSd listdensityplot listplot listplotSd loglogplot logplot matrixplot multiple odeplot pareto As with display we can use with to load all the functions in the plot package in expectation of using several The first parameter to an i mate is the name plotcompore pointplot pointplotSd polorplot polygonplot polygonplotSd polyhedrosupported polyhedroplot rootlocus semilogplot setcolors setoptions setoptionsSd spocecurve sporsenmtrixplot surfdoto textplot textplotSd tubeplot onimoteplot sinAx x 0 10 A 0 2 A20 onimotepointplot x x2 2 x color 2 red x 0 2fromes 50 x 0 09 06 04 02 00 05 1 15 2 net pointplot l8 0 21 0 color 2 green symbolsize 40 PLOT 152 onimote pointplot lx x2 2 xl color of a plotting function The second parameter is a list of arguments to be giving to that plotting function The expression to be plotted has an extra parameter in this case A that controls how things change from frame to frame Thus the first frame will be pl 0t 51 n 0 X XO 10 The second frame willbe pl otS i n 083333X X 0 10 the next frame pl otS i n 16667X XO 10 etc A increments in steps of 225 are being used because the range is from 02 and we are using the default number of frames which is 25 Animate labels each frame with the value of A being used This is another example of animate The first frame is the plot produced by pO i ntpl 0t 0 OA22 0 col or r ed The second frame is pointplot110 110quot22 110 etc The number of frames in the movie is specified as an additional argument 2 red x 0 2fmmes 50 background 2 net labels 2 quotdistancequot quotheightquot x 0 09 06 height 0 4 02 0 O 0 05 1 1 5 2 distance We create a non animated plot structure that depicts a net that stretches from 180 to 21 0 An additional argument to animate is an equation background p where p is a plot structure It is drawn in every frame of the animation as quotbackgroundquot If we make net the background in our animation we will see the ying point land in the quotnetquot

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

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

#### "I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I 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."

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

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