Document 12910998

advertisement
Andrea Martinez Vernon Hamish Peter Todd CH925 MATLAB’s ode45 function MATLAB’s ode45 function solves initial value problems of nonstiff differential equations with medium order accuracy. Nonstiff differential equations can be solved using ‘steps’ and have a solution with numerical stability. The solver uses an explicit Runge-­‐Kutta formula to make error estimates and adjust the time step accordingly. Matlab recommends it as a “first try” for most problems. By default the relative error tolerance is 1x10-­‐3, which corresponds to 0.1% accuracy. The general MATLAB code for ode45 is: [T,Y] = ode45(odefun,tspan,y0,options), where: odefun is the ODE function to be solved, tspan is the time interval given by [initial_time, final_time], y0 is the initial condition, options are the specified parameters (see below). NOTES: -­‐The ODE function must have an output with an array structure in order to work (see example 1). -­‐The solution can be plotted directly by using ‘T’ as x and ‘Y’ as y as in: plot(T,Y) To set the parameters within ‘options’ the odeset function is used: options= odeset(‘optionname1’, value1, ‘optionname2’, value2,…) OPTIONS Allows certain parameters to be specified. These can be classified in the following categories: § Error Control o ‘AbsTol’, ‘RelTol’, ‘NormControl’ are about error. o ‘RelTol’ is relative total error, ‘AbsTol’ is absolute total error. o ‘NormControl’ gives you a sensitive combination of the two. § Example code: options=odeset(‘RelTol’, 0.4) § Solver Output o ’Stats' displays failed attempts, successful attempts etc. o ‘Refine’ gives you more points. § § Step-­‐Size o ‘InitialStep’ sets the suggested initial step size § Event Location o EXCEPTION! o Uses a function to determine a condition that will affect the integration process § CODE: [value,isterminal,direction] = events(t,y) § Mass Matrix and DAE o ‘MassMatrix’ and ‘MStateDependence’ allow you to bring in matrices, solving things of the form M(t,y)y’ = f(t,y) <For a full list of parameters in ode45 visit: http://www.mathworks.co.uk/help/matlab/ref/ode45.html> EXAMPLES 1. NonNegative Translates the graph until all “y” values are positive 2. Event ‘Options’ exception! Instead of using a value, a function is required to set the event parameter conditions. !!
Problem: !"! = −𝑘𝐶 !! , 𝐶! !!! = 2.3𝑚𝑜𝑙/𝐿 and 𝑘 = 0.23 𝐿/𝑚𝑜𝑙/𝑠. Compute the time required to obtain 𝐶! = 1 𝑚𝑜𝑙/𝐿
Download