1 / 65

Engineering Problem Solving with Computers

Engineering Problem Solving with Computers. MEPP Summer Residency August 2008. Outline for Session. About me Course overview Cases Excel programming and Optimization Matlab Primer. Intro. Jake Blanchard, Professor, Engineering Physics PhD in Nuclear Engineering, UCLA, 1988

koren
Télécharger la présentation

Engineering Problem Solving with Computers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Engineering Problem Solving with Computers MEPP Summer Residency August 2008

  2. Outline for Session • About me • Course overview • Cases • Excel programming and Optimization • Matlab Primer

  3. Intro • Jake Blanchard, Professor, Engineering Physics • PhD in Nuclear Engineering, UCLA, 1988 • Research: fusion technology, solid mechanics, nuclear batteries for MEMS, laser effects in metals • Born and raised in Southern California • married with two kids (11 and 9 yrs)

  4. My Research Interests • Fusion Technology • Fission Reactor Fuels and Structures • Nuclear Microbatteries

  5. Goal of EPSC • Students who have completed this course should have a broad understanding of: • Solution techniques for several equation types • Level of difficulty for various problem types • Appropriate tools for solving various problems • Advantages and disadvantages of using computers to solve engineering problems

  6. Goal of This Session • I just want to get you started with the tools we use in my course • My theory is that some exposure now will benefit you in the Spring • We will repeat everything we do today when the course starts, though in more depth • Therefore, don’t worry if you don’t catch on to everything right away

  7. Approach Used in EPSC • Problem-based using case studies • Assigned and student-identified projects • No exams

  8. Textbooks • We will use a text I put together from two full texts: one Excel-based and one Matlab-based • You won’t all need this and no problems will be assigned from it • Buy it from Rose • Many other background books are available if you need additional support

  9. Numerical Topics • Linear and nonlinear equations • Quadrature • Ordinary differential equations • initial value • boundary value • Optimization • Data Analysis • Databases

  10. Prerequisites and Resources • Math skills: linear algebra (matrices and vectors) and ordinary differential equations (first and second order) • Computer skills: some programming is useful, but not necessary

  11. Used These Before? • FORTRAN • C • C++ • Pascal • Basic • Java • Others? • EES • MathCAD • Matlab • Excel/Quattro • Mathematica • Maple • Others?

  12. Tools • Microsoft Excel (97, 2000, 2003, etc.) • Matlab from Mathworks • there is a student version for ~ $100 • Any version beyond Matlab 4 will work fine, though a couple things got easier with version 6 and a few commands have changed • You can run it as “tethered” software from CAE if you are interested (www.cae.wisc.edu/tethered)

  13. Cases • Broad coverage of engineering disciplines and topics • The more students can see relevance of cases, the better

  14. Case Titles and Topics • Macros in Excel • Databases • Material Properties (choose your own for lesson) • Quadrature • Automobile suspension • Roots • natural frequencies of satellite boom • Linear Systems • fluid flow network

  15. Case Titles and Topics • Initial Value • PSII target heating • Boundary Value • chip cooling • Optimization (Linear Programming/Constraints) • manufacturing

  16. Case Titles and Topics • Optimization (Monte Carlo) • maximize profit with uncertain inputs • Curve Fits • radioactive decay

  17. Hands-On Session • Optimization Problem in Excel (using the Solver) • Introduction to Matlab

  18. First Download Files http://www.cae.wisc.edu/~blanchar/MEPP.html

  19. Optimization of Water Distribution • Consider two bottling plants: Mexico City and Tepic • Consider three customers: one in Monterrey, one in Mazatlan, and the other in Acapulco • Question is: which plants should ship to which cities?

  20. Plant Data

  21. Customer Data

  22. Best Guess • Use pencil and paper to make best guess of optimum distribution • Goal is to meet demand with minimum cost • Selling price is the same in each city

  23. Sheet Setup What is total cost for your guess at the optimal distribution?

  24. Using the Solver • Tools/Add-Ins…Solver • Tools/Solver • Take a look at this link for further information: http://econltsn.ilrt.bris.ac.uk/cheer/ch9_3/ch9_3p07.htm

  25. The Main Solver Window

  26. Dialog for Adding Constraints

  27. Results Dialog

  28. Your Task • Set up the Solver, with all appropriate constraints, to optimize this problem

  29. Next Scenario • What if the production cost in Tepic drops to 0.45 $/gal?

  30. Next Scenario • What is optimum if demand increases in each city by 50%? Put Tepic back at 0.6 $/gal on the production cost.

  31. Adding a “Run” Button • Excel has a built-in macro language called Visual Basic for Applications (VBA) • It can be used to create user interfaces • We can use it to add a button for running the Solver

  32. Using Macros • Macros are written in a Basic-like language called Visual Basic for Applications • Excel comes with a separate macro editor • To create or edit a macro, go to Tools/Macro/Visual Basic Editor • To add a new module go to Insert/Module

  33. The Macro Sub runsolver() SolverSolve End Sub

  34. Creating the Button • Go to View/Toolbars/Forms • From this Toolbar, click on the button (row 2, column 2) and then trace out a button on a spreadsheet • Assign the “runsolver” macro to the button • Now click the button • Note that you may have to add a “Reference” to the Solver under Tools in the VBA Editor

  35. User-Defined Functions • We can also create user-defined functions in VBA • These can be called from cells, just like any built-in function

  36. Creating a Function • Suppose we want to create an Excel function that takes a temperature in Celsius and converts to Fahrenheit • We would type the following in a module: Function ctof(temp) ctof = 9 / 5 * temp + 32 End Function

  37. Using the function • Then you can go to the spreadsheet and type =ctof(100) • Or, you can put the value of “100” into cell A1 and then type =ctof(A1) into some other cell • In fact, this function can be used just as any built-in Excel function can be used

  38. Exercise • Copy this function and create ftoc for converting from fahrenheit to celsius

  39. The Macro Language • Operators: +, -, *, /, ^, Mod • Comparison: =, <, >, <=, >=, <> • Logical Operators: And, Eqv, Imp, Not, Or, Xor • Intrinsic Functions: Abs, Cos, Sin, Tan, Atn (arc tangent), Exp, Log (natural), Sgn, Sqr (square root), Rnd (random number)

  40. Flow Control If condition Then statements Else statements End If If x=0 Then f=1 Else f=sin(x)/x End If

  41. Flow Control For counter=start To end statements Next For i=1 To 100 sum=sum+i Next

  42. Flow Control Do Until condition statements Loop i=1 x=1 Do Until i=50 x=x*i i=i+1 Loop

  43. Flow Control Do While condition statements Loop i=1 x=1 Do While i<50 x=x*i i=i+1 Loop

  44. Example • Write an Excel function that calculates the factorial of some number Z • Factorial is Z*(Z-1)*(Z-2)*…*3*2*1

  45. My solution Function fact(Z) x = 1 ans = 1 Do Until x = Z ans = ans * x x = x + 1 Loop fact = ans End Function

  46. Another Solution Function fact(Z) ans = 1 For i = 1 To Z ans = ans * i Next fact = ans End Function

  47. Exercise • Write an Excel function that calculates the sum of the first N cubes and test it • That is: 13+23+33+…+N3 • What is the result for N=20?

  48. Matlab • Matlab began as a linear algebra package • It’s grown to be a general purpose equation solver • Strengths: robust routines, excellent performance • Weaknesses: more difficult user interface

More Related