PH36010 Numerical Methods Solving Differential Equations using MATHCAD.

Presentation on theme: "PH36010 Numerical Methods Solving Differential Equations using MATHCAD."— Presentation transcript:

PH36010 Numerical Methods Solving Differential Equations using MATHCAD

Solving ODEs numerically Produce numeric solution to system of ODEs.Produce numeric solution to system of ODEs. Must have initial conditionsMust have initial conditions Use one of several different solversUse one of several different solvers Produces matrix of solutionsProduces matrix of solutions

Steps to solving ODEs Scale equations, parameters & initial conditions to remove unitsScale equations, parameters & initial conditions to remove units Manipulate equations to give vector of derivativesManipulate equations to give vector of derivatives Give vector of initial conditionsGive vector of initial conditions Call solverCall solver Plot resultsPlot results

Radioactive decay, Newton’s law of cooling etcRadioactive decay, Newton’s law of cooling etc A is amount of material, temperature difference, etcA is amount of material, temperature difference, etc k is rate constantk is rate constant Solution of First Order ODE

Forming the derivative vector “The derivative of A with respect to t is –k times A”“The derivative of A with respect to t is –k times A”

Initial Conditions First order ODEFirst order ODE –1 member of D(t,A) vector –1 member of ic vector Although only 1 member, still needs to be a vector

Solution parameters TStart and TFinish timesTStart and TFinish times Number of points, NNumber of points, N

Create Solution Matrix Use rkfixed() functionUse rkfixed() function Return matrix with 1 column per DE + 1 for independent variableReturn matrix with 1 column per DE + 1 for independent variable Use column operator to strip off columnsUse column operator to strip off columns

Plot Results

What can go wrong Found number greater than 10^307Found number greater than 10^307 –Use more points –Reduce TFinish Can’t have anything with dimensions hereCan’t have anything with dimensions here –Strip units from system before solution

More complex first order system Double decayDouble decay A => B => CA => B => C K1 K2 K1 K2

Forming the derivative vector

Initial Conditions System of 2 DEsSystem of 2 DEs –2 members in D(t,F) vector –2 members in ic vector F 0 refers to A => ic 0F 0 refers to A => ic 0 F 1 refers to B => ic 1F 1 refers to B => ic 1 Initially 100% of A, 0% of B

Form Solution of Double Decay system Solution parameters as beforeSolution parameters as before Call rkfixed() as before to create matrixCall rkfixed() as before to create matrix

Plot results of double decay

Second Order System Damped SHM Rewrite as system of first order equationsRewrite as system of first order equations Solve as beforeSolve as before

Second Order system LCR Circuit Kirchoff’s Voltage Law =>

Second order System Forming the equations Use dq/dt=i and divide by L coil To get homogeneous equation in q

Second Order System Writing standard form #1 Rewrite again, getting rid of d/dt

Second Order System Writing standard form #2 Use symbolic solver to get q2

Second Order System Fill in D vector Have expressions for q1 & q2Have expressions for q1 & q2 Now fill in D(t,q) vectorNow fill in D(t,q) vector ReplaceReplace –q0  q 0,q1  q 1,q2  q 2

Second Order System Define Initial Conditions Start with 1V across capacitor & no current flowingStart with 1V across capacitor & no current flowing

Second Order System Create Solution Examine over 0.1sExamine over 0.1s Use 1000 pointsUse 1000 points

Second Order System Plot Solution

Driven Systems So far all systems have been ‘Relaxation to steady state’So far all systems have been ‘Relaxation to steady state’ Can also model systems driven by ‘Forcing Function’Can also model systems driven by ‘Forcing Function’

Forcing Function for LCR circuit Enables us to see resonanceEnables us to see resonance Put voltage source in loopPut voltage source in loop

Solution for Forced Oscillation Use symbolic solver to solve for q2 as beforeUse symbolic solver to solve for q2 as before Compare with undriven case…Compare with undriven case…

Forcing function Drive with sinusoidal waveformDrive with sinusoidal waveform Substitute to give…Substitute to give…

Derivative Vector for Forced SHM No initial charge or currentNo initial charge or current

Form solution Use rkfixed as before…Use rkfixed as before…

Extract values & plot

Phase Plot Plot Current (q1) vs Charge (q0)Plot Current (q1) vs Charge (q0)