1 / 24

An Introduction to MathCAD

An Introduction to MathCAD. You can always find a solution !!. When things go wrong. “Result is too large to Display”. Can we fix it ? Yes we can !!. Force solver to work with real numbers. What if its still broken ?. Risky !! – OK in this case. Still can’t solve it ?.

crete
Download Presentation

An Introduction to MathCAD

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. An Introduction to MathCAD You can always find a solution !!

  2. When things go wrong “Result is too large to Display”

  3. Can we fix it ?Yes we can !! Force solver to work with real numbers

  4. What if its still broken ? Risky !! – OK in this case

  5. Still can’t solve it ? • Use polyroots to find roots • Use coeffs keyword on solver to get coefficients of x

  6. Still can’t solve it ? • Graph shows maxima & minima • => there must be solutions • Try guessing & using roots(f1(x),x)

  7. Solving ODEs numerically • Produce numeric solution to system of ODEs. • Must have initial conditions • Manipulate equations • Use one of several different solvers • Produces matrix of solutions

  8. First order linear ODE#1 • Radioactive decay, Newton’s law of cooling etc • A is amount of material temperature difference etc • k is rate constant

  9. First order linear ODE#2 • Define initial conditions as a vector • 1st order so only 1 element in vector • Can’t use units in ODE solver • Call vector ‘ic’ • Element 0 = A at t=0

  10. First order linear ODE#3 • Now define ODE & manipulate for mathCAD

  11. First order linear ODE#4 • Now define range of solution Start time Finish Time Number of Points • And solve using rkfixed • Creates matrix ‘Soln’ containing solution

  12. First order linear ODE#5 The Solution Matrix Column 0 holds t values Column 1 holds A values 1 row of matrix per timestep (0..N)

  13. First order linear ODE#6 • Plot the results • Use M<> to extract columns • Use subscripting to extract rows

  14. Second Order ODE • Same steps as for first order • Slightly less obvious manipulation • Replace ODE by system of 1st orders • Can use symbolic solver to formulate equations

  15. Second Order ODEExample #1 • Damped SHM • LCR circuit • Damped Pendulum Substitute for i & divide through by L Gives:

  16. Second Order ODEExample #2 Gives manipulatedequation:

  17. Second Order ODEExample #3 • Use solver to solve for q2 • Now ready to create D(t,q) function

  18. Second Order ODEExample #4 • Equations to create D(t,q) • 2 row vector to hold D(t,q) • Change subscripts for suffixes

  19. Second Order ODEExample #5 • Specify initial conditions • For second order need 2 elements in ic vector Charge (q) at t=0 Current (dq/dt) at t=0 • Also need to specify constants in D(t,q) equations • Watch for lack of units !!

  20. Second Order ODEExample #6 • Define times and number of points as before • Call rkfixed to solve • Matrix Soln filled with solution points

  21. Second Order ODEExample #7 • The solution matrix Column 0 holds t values Column 1 holds q values Column 2 holds dq/dt values

  22. Second Order ODEExample #8 • Graphing the solution

  23. Surely nothing can go wrong ? • Solution relies on numeric integration which divides timestep up into smaller chunks for integration • If system is changing much faster than timestep, solution will fail • Clues to look for: • “found a number >10^307” • Singularity at tfinish

  24. Can we fix it ? • Check time constants • Try more point in solution (N) • Try smaller interval • Use a different solver • ‘Stiff’ systems give problems • Special solvers for stiff systems • See Quicksheet & help system

More Related