Download presentation
Presentation is loading. Please wait.
Published byMadlyn Davidson Modified over 8 years ago
1
CS 122/CS123 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Summer 2011 ©By the author. All rights reserved. Permission is given to CS123 Summer 2011 staff and students to use and reproduce these notes for their own use.
2
Review of Lab 1 Cycle – CS122/CS123 Major Lab 1 concepts to remember – cs122 – Use of code edit regions to develop, test and debug scripts – Use of user defined functions to facilitate script development – Troubleshooting / debugging techniques (including Maple’s print functions) Major Lab 1 concepts – cs123 – “for” loop to enact time staged simulation – Mechanics and placement of acState and airFlowcontrol procedures to: acState – determine whether high or low flow is necessary airFlowControl0 – set value of hi/lo flow based on present state from acState
3
Some Administrative Notes and Guidelines Be sure to check lab and quiz results on bbVista as soon as posted and report issues to your instructor immediately. It is important to resolve issues as soon as they occur Quiz support – Try to take the quiz prior to Friday afternoon – Use the Wednesday session for quiz support – You may take the quiz multiple times; only your highest result will count Please contact your instructor with any questions or problems
4
Getting Started Sign verification sheet (print neatly) with partners Bring up Lab 2 description from course website – www.cs.drexel.edu/complab/cs123/summer2011 www.cs.drexel.edu/complab/cs123/summer2011 – www.cs.drexel.edu/complab/cs122/summer2011B Launch Maple 15 session Work as a team to solve the problems as per the lab description At end of lab: – get verification sheet signed (as team completes each part) – SAVE your worksheet (email to team or save to bbVista)
5
Quiz 2 Activities Quiz 2 will be released on Tuesday (8/2) at 9 am – Deadline: Friday (8/51) at 5 pm Pre-lab quizlet for Lab 3 – released on Thursday (8/4 at 9 am) through Monday (8/8 at 3 pm)
6
Lab 2 Overview – CS122 Based on materials from Chapter 12 and 13 readings – More script development, revisions from starter scripts – More practice with user defined functions – More usage of Maple’s plot features – line plots, multiple plots on same graph – Introduction on Maple’s table data structure – chapter 12 – Repetition using “for” loops – chapter 13
7
Lab 2 Overview – CS122 Lab 2 outline – Problem 1.1 A. revising a starter script to draw a red box B. and C. develop a user defined function to draw the box D. create an enhanced script that also lets the user define the position (lower left corner) of the box E. develop a script within a code edit region that calls functions to draw a variety of boxes on the same graph Will be used in Lab 4 where we simulate a particle bouncing around in a box – Part 2 – plotting time staged results of chemical reactions 2.1 – complete a starter script to add additional component concentration results to tables and plot a single concentration over time 2.2 – use tables and for loops to extend the script from 2.1 to plot results of all 4 chemical component concentrations over time
8
Lab 2, Part 2 programming concepts It’s easy to see what code gets repeated: – What’s between the “for” and the “end do”. – Indentation helps readability. Pattern: Each repetition of the loop computes the level of a chemical at a particular time. Result: you compute the level of the chemicals at many different points in time. Use the index variable of the loop to place values in table(s).
9
Simulating Time Steps with Loops # Set up initial concentrations A := A0; B := B0; X := X0; Y := Y0; for i from 1 to numTimeSteps do newA := A - k1*A*X; … A := newA; indexTab[i] := i; Atab[i] := A; end do: display([Fplot(indexTab,Atab,"Green")], title="graph of A", labels=["time", "concentration"]);
10
Lab 2 programming concepts Pre loop processing – All the variables in the loop (except for the index variable) have to be initialized in a statement executed before the loop starts working. Post loop processing – Take all the value placed in the table, turn them into a list of values. – Plot the lists using plot as we’ve done before.
11
Lab 2 Maple Concepts: Observation on programming style Name user defined functions descriptively – Eg. Plot2lines versus P2 Use comments (#) within code edit regions to explain complex code or operations Indent statements within “for” loops – for i from 1 to 10 do statement 1 * statement n end do;
12
Lab 2 Maple Concepts: Part 0 Practice now with Maple features needed for this lab – The following concepts are illustrated Example 1 – Maple’s line plotting feature – User defined functions Example 2 – Code edit region – Maple’s table data structure and “for” loop feature – User defined functions
13
Lab 2 Overview – cs123 Based on materials from Chapters 15 and 16 – Chapter 15 – Using Maple’s Procedure feature Transform the AC simulation from Lab 1 into a Maple procedure – Chapter 16 – Creating User Interfaces with Maple Components Use of slider, button and plot area components to control the AC simulation procedure
14
Lab 2 Overview – cs123 Lab 2 outline – Part 1.1 – Converting the AC simulation to a Maple procedure Open your AC simulation script from Lab 1 along with the model template from the course web site Copy and paste code segments from your Lab 1 script into appropriate sections of the model template Run the 3 tests from the scripts provided on the course web site – Part 1.2 – User interface for the AC procedure Use the final procedure developed in part 1.1 and develop a user interface to control the high and low AC air flow settings and to invoke the simulation – see Part 0 exercise for user interface creation
15
Lab 2 Maple Concepts: Discussion and Demo – cs123 Part 1.1 – Maple Procedure Syntax – Procedure header – 1 st line of a Maple procedure HVAC1:=proc(totaltime, dt,aFunc,fFunc,T0,Tea,lf,hf) – Local variable declaration local N, A, L, T, U, V, c, q, rho, Zplot, EWplot, i, Time, state, Tew; – Return (will return a plot display for the temperatures vs. time) return plots[display]([Zplot,EWplot]); – Procedure end statement end; or end proc; These statements appear in the model template script. Cut and paste segments of your Lab 1 script into this script in the appropriate locations.
16
Lab 2 Maple Concepts: Discussion and Demo – cs123 Part 1.2 - Demo of Maple User Interface Components – The instructor will open a Maple worksheet and develop a user interface for the plot of the sin function in which a slider is used to define the period of the sin function. – Step 1 – Identify the necessary Maple Components Slider – set to a value between 1 and 10 to define the period Text Area – shows the slider setting numerically Plot Area – box into which the plot will appear “Draw Plot” button – click to create the plot graph – Step 2 – Open the Components Palette and drag the components into the work sheet Create a tale to organize the components – insert table (3x2) – Slider into row 1, column 1 – Text Area into row 2, column 1 (add text “Value” to left of button) – Button into row 3, column 1 – Plot area into row 1, column 2
17
Lab 2 Maple Concepts: Discussion and Demo – cs123 Part 1.2 - Demo of Maple User Interface Components – continued – Step 3 – Configure each component (right click on the component and open “component properties”) Slider – name=PlotSlider, range (0 to 10), ticks (major=5, minor=1), “show axis labels”, “update continually while dragging” Text Area – name=kText, number of visible rows = 1, “not editable” (slider will determine the k value) Plot Area – name = sinPlotter “Draw Plot” button – Caption = “Draw Plot”
18
Lab 2 Maple Concepts: Discussion and Demo – cs123 Part 1.2 - Demo of Maple User Interface Components – continued – Step 4 – Program each component (right click on the component and open “component properties” Edit – Action when contents change) – just before “end use;” statement at end of region Slider – Do( %kText = %PlotSlider) “Draw Plot” button – Do( %sinPlotter = plot(sin(%PlotSlider*x), x=0..10, color=red)); – Step 5 – Run the program from the user interface Test 1 – set slider to 8 and click “Draw Plot” button Test 2 – change slider to 1 and click “Draw Plot” button
19
Lab 2 Maple Concepts: Discussion and Demo – cs123 Part 1.2 - Demo of Maple User Interface Components – continued Note – the “Draw Plot” button for Part 1.2 should be programmed as follows: – Do( %nameofplotarea = plots[display] (HVAC1(30, 0.01, acState, airFlowControl0, 90, 65, %lowFlowSlider, %highFlowSlider))
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.