CS123 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Spring 2010
Administrative Notes Please contact your individual instructors with questions and problems!! At this time, is anyone still having a MapleTA login issue?
Lab 2 Overview Based on materials from Chapters 15, 16 and 17 –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 –Chapter 17 – Calculus and Optimization Develop an objective function for the minimum surface area of a can and find optimal dimensions (radius and height) using Maple’s Optimization feature
Lab 2 Overview 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 demo for user interface creation –Part 2 – Find the minimum dimensions of a can that holds a specified volume of liquid using Maple’s Optimization function Create an expression for the can’s surface area (objective function) to hold a constant volume of liquid Use the Maple Optimization function to find the minimum dimensions (radius and height) for the surface area
Lab 2 Maple Concepts: Discussion and Demo 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.
Lab 2 Maple Concepts: Discussion and Demo Part 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
Lab 2 Maple Concepts: Discussion and Demo Part 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”
Lab 2 Maple Concepts: Discussion and Demo Part 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
Lab 2 Maple Concepts: Discussion and Demo Part 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))
Lab 2 Maple Concepts: Discussion and Demo Part 2 – Maple’s Optimization feature –Creating the Objective function (surface area of a can) Surface area = lateral area + top and bottom SA = 2*pi*r*h + 2*pi*rsquared –Since the surface area needs to be a function of a single variable (eg. radius=r), we need to find an function relating h (height) to r and substitute. Since the volume is constant at 1000: 1000 = pi*rsquared*h h = 1000 / (pi*rsquared) Substitute this equation for h into the SA equation above to obtain the objective function SA(r).
Lab 2 Maple Concepts: Discussion and Demo Part 2 – Maple’s Optimization feature –Now use this objective expression SA(r) to find the minimum surface area over a range of radii that holds a volume = 1000 –minRslt:=Optimization[ Minimize](objexpression,r=1..10) You will obtain 2 results minRslt[1] minimum surface area minRslt[2] radius that produces this minimum SA –Substitute minRslt[2] into the equation for h to obtain the associated height
Quiz Week (5) Activities Quiz 1 will be released on Friday (4/23) at 6 PM –Deadline: Wednesday (4/28) at 4:30 PM –Makeup quiz – from Thursday (4/29) at 9 AM through Sunday (5/2) at 11:30 PM 30% penalty Pre-lab 3 quizlet –From Thursday (4/29 – noon) through Monday (5/3 – 8 AM) Be sure to visit the CLC for quiz or general Maple assistance