This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: MATLAB Lecture 3 1. Introduction Today we will use MATLAB to numerically solve ordinary differential equations. 2. Differential Equations They dynamic behavior of systems is an important subject. A mechanical system involves displacements, velocities and accelerations. An electric or electronic system involves voltages, currents and time derivatives of these quantities. An equation that involves one or more derivatives of the unknown function is called an ordinary differential equation or ODE. The order of the ODE is the order of the highest derivative appearing within the equation. The problems of solving an ODE are classified into initial value problems (IVP) and boundary value problems (BVP), depending on how the conditions at the endpoints of the domain are specified. All the conditions of an initial-value problem are speci- fied at the initial point. On the other hand, the problem becomes a boundary-value problem if the conditions are needed for both initial and final points. The ODE in the time domain are initial-value problems, so all the conditionsa re specified at the initial time, such as t = 0 or x = 0. For notations, we use t or x as an independent variable. 3. Analytic Methods MATLAB is capable of solving many differential equations. There is a built-in function dsolve which takes care of things in one fell swoop, all we need to know is how to plug in the differential equation. Example 3.1. Lets find the general solution of the differential equation dy dt + 2 ty = t We enter this as follows: dsolve(Dy+2*t*y=t,t) We get the following answer: C2/(2*exp(t^2))+1/2 Equivalently, C 2 e t 2 + 1 2 where C is a constant. Note that MATLAB interprets Dy as the derivative of y , or y , and the t by itself indicates the independent variable. Also note that since we are not entering a function, we dont need the special versions of * , ^ and / . MATLAB gets even better. It can deal with an initial condition too using dsolve . Lets solve the same differential equation with the initial condition that y (0) = 2. 1 dsolve(Dy+2*t*y=t,y(0)=2,t) And get the following output: 3/(2*exp(t^2)) + 1/2 Lets finish up by plotting this solution on the interval [0 , 2]. t=0:.1:2; f=matlabFunction(dsolve(Dy+2*t*y=t,y(0)=2,t)) y=f(t); plot(t,y) In the above code, I used the command matlabFunction because dsolve outputs a symbolic answer and I needed a function in order to plot the graph ( ezplot can get around this, but it has limited capabilities). Youll notice that dsolve initially outputted the solution 3/(2*exp(t^2)) + 1/2 and matlabFunction changed it to @(t)exp(-t.^2).*(3.0./2.0)+1.0./2.0@(t)exp(-t....
View Full Document