{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

matode

# matode - Solving ODE in MATLAB P Howard Fall 2007 Contents...

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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solving ODE in MATLAB P. Howard Fall 2007 Contents 1 Finding Explicit Solutions 1 1.1 First Order Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Second and Higher Order Equations . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Finding Numerical Solutions 4 2.1 First-Order Equations with Inline Functions . . . . . . . . . . . . . . . . . . 5 2.2 First Order Equations with M-files . . . . . . . . . . . . . . . . . . . . . . . 7 2.3 Systems of ODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.4 Passing Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.5 Second Order Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3 Laplace Transforms 10 4 Boundary Value Problems 11 5 Event Location 12 6 Numerical Methods 15 6.1 Euler’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 6.2 Higher order Taylor Methods . . . . . . . . . . . . . . . . . . . . . . . . . . 18 7 Advanced ODE Solvers 20 7.1 Stiff ODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1 Finding Explicit Solutions MATLAB has an extensive library of functions for solving ordinary differential equations. In these notes, we will only consider the most rudimentary. 1 1.1 First Order Equations Though MATLAB is primarily a numerics package, it can certainly solve straightforward differential equations symbolically. 1 Suppose, for example, that we want to solve the first order differential equation y ′ ( x ) = xy. (1.1) We can use MATLAB’s built-in dsolve(). The input and output for solving this problem in MATLAB is given below. >> y = dsolve(’Dy = y*x’,’x’) y = C1*exp(1/2*xˆ2) Notice in particular that MATLAB uses capital D to indicate the derivative and requires that the entire equation appear in single quotes. MATLAB takes t to be the independent variable by default, so here x must be explicitly specified as the independent variable. Alternatively, if you are going to use the same equation a number of times, you might choose to define it as a variable, say, eqn1 . >> eqn1 = ’Dy = y*x’ eqn1 = Dy = y*x >> y = dsolve(eqn1,’x’) y = C1*exp(1/2*xˆ2) To solve an initial value problem, say, equation (1.1) with y (1) = 1, use >> y = dsolve(eqn1,’y(1)=1’,’x’) y = 1/exp(1/2)*exp(1/2*xˆ2) or >> inits = ’y(1)=1’; >> y = dsolve(eqn1,inits,’x’) y = 1/exp(1/2)*exp(1/2*xˆ2) Now that we’ve solved the ODE, suppose we want to plot the solution to get a rough idea of its behavior. We run immediately into two minor difficulties: (1) our expression for y ( x ) isn’t suited for array operations (.*, ./, .ˆ), and (2) y , as MATLAB returns it, is actually a symbol (a symbolic object ). The first of these obstacles is straightforward to fix, using vectorize() ....
View Full Document

{[ snackBarMessage ]}

### Page1 / 22

matode - Solving ODE in MATLAB P Howard Fall 2007 Contents...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online