[t,y]=solver_name(‘ODEfunc’,tspan,y0)
ODEfunc is the name of the function file which defines the differential equation, the f(t,y).
tspan is a vector that specifies the interval of the independent variable spanned by the solution.
y0 is the initial value of y.
[t,y] is the output, in the form of two column vectors. Subsequently, we would plot(t,y).
a. Function file
The function file calculates for given values of y & t. That is, t & y are input arguments to the function, and the value of f(t,y) is returned.
b. Solvers
Table 9-1 lists some of the MatLab® initial-value ODE solvers. Some are more sophisticated than others; some are adapted to problems in which the solution is not smooth, or is rapidly varying, etc. In most physical and engineering applications, things are smooth and not too-rapidly varying, so most times ode45 should suffice.
[t,y] = ode45(‘function’,[0:0.1:10],100)
plot(t,y)
MatLab® also has boundary value and partial differential equation solvers, but those are not discussed in the introductory text, nor in this class.
example: Problem 9-35
v0 = 300/60/60*1000
[t,v] = ode45(‘drag’,[0:0.1:15],v0)
plot(t,v)
function dvdt = drag(t,v)
dvdt = -0.0035*v*v-3;
Share with your friends: |