Download presentation
Presentation is loading. Please wait.
Published byWillis Malone Modified over 9 years ago
1
Solving ODEs UC Berkeley Fall 2004, E77 http://jagger.me.berkeley.edu/~pack/e77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. http://jagger.me.berkeley.edu/~pack/e77http://creativecommons.org/licenses/by-sa/2.0/
2
Numerical Soln of Differential Equations Recall the population problem you worked out in HW –Independent variable: time. –Dependent variables: eggs, larvae, adults –Governing rule for their “one-step” evolution An initial condition (values for e 0, v 0 and a 0 ) and a for loop leads to the solution (over time). Here, the variables evolve discretely in time. This is called a discrete-time equation. What if the variables evolve continuously in time?
3
Differential Equations Applying the “conservation laws” that make up a scientific field often leads to differential equations. Examples –“rate of change of linear momentum of a mass particle” equals the forces applied to the particle –“rate of change of internal energy of a system” equals the net flow of energy into the system –“rate-of-change of concentration of a molecule” equals a sum of terms proportional to the products of concentrations of other molecules Rate-of-change means derivative. We’ll use to denote derivative of y with respect to its argument. If the argument is time, convention is to use to denote derivative.
4
Ordinary Differential Equations Initially, use the following notation –Independent variable, x –Dependent variable, y y is a function of x, y(x) (notate the derivative as y´(x)) –Known function, f Given information –Initial condition The value of y(0) is known, say y 0 –The “governing equation,” which gives y´ in terms of y Goal: find “solution”, namely a function y which satisfies –The initial condition, and –The governing equation for all x Fact: For most right-hand-sides, there exists a unique soln The rate-of-change of y at x depends only on the value of x, and the value of y(x)
5
Example: Ordinary Differential Equations Consider a simple example Exact Solution is easy: Consider a less-simple example Exact solution is (integrating factor)
6
Ordinary Differential Equations An “initial value” problem –the initial value of y as known/given –the goal is to compute y for “later” (more positive) values of x. A “final value” problem –the final value of y as known/given –the goal is to compute y for “earlier” (less positive) values of x. A “boundary value” problem –the initial value of some components of y is known/given –the final value of some components of y is known/given –the goal is to compute y for the intermediate values of x. Initial value and final value problems are basically the same. Boundary value problems are different.
7
Ordinary Differential Equations Initially, use the following notation –Independent variable, x –Many dependent variables, y 1, y 2, …, y n –Known function, f Given information –Initial condition The value of y(0) is known, say y 1,0, y 2,0, …, y n,0 –The governing equation, which gives y´ in terms of y The rate-of-change of y at x depends only on the value of x, and all of the values of y(x)
8
Coupled, 1 st -order Ordinary DiffEq Use the following terminology –Coupled, since there are n dependent variables, and their values influence the rate-of-change of each other –1 st order, since only 1 derivative appears –Ordinary, since there is only one independent variable Write concisely
9
Satellite orbiting Earth The motion of a point-mass, m, orbiting a stationary massive object M is governed by Accelerations in radial and tangential directions Forces in radial and tangential directions
10
Converting to first-order form Starting with Define Write each in terms of all of the Two, 2 nd -order coupled ODEs
11
Beam Theory (CE 130) Consider a beam. Under the influence of a distributed load... The relationship between the load, w(x), and the transverse deflection v(x) is Boundary-value problem! w(x), distributed load, in Newtons/meter, function of location it deflects!
12
Beam Theory: convert to first-order form Governing equation is With boundary conditions Define reformulated
13
Euler Approximation to solution Write the system of equations Here, f maps a scalar (x), and an n-by-1 vector (y) into a n-by-1 vector. Consider an IVP. The value of y at x 0 is given as y 0. What is the solution for x>x 0 ?
14
Euler Approximation to solution At x 0, the governing equation implies Use forward finite difference approximation to the left- hand side (ie., the derivative) Equate these, giving the approximate value for y(x 0 +h) known
15
Euler Approximation to solution The Euler approximation to the solution is obtained by repeating this process using –the forward finite difference approximation to the derivative, and –the approximate solution as the value of y at x 0 +h. The forward finite difference says But we don’t know these. Approximate value is available via the previous step, Use this approximate value, and continue in this fashion.
16
Euler Approximation to solution Let y E denote the Euler solution. Specifically, denotes the approximate solution at the k th “step”. Using a stepsize of h, the Euler approximate solution is evolved (as a discrete equation)
17
Euler psuedo-code function [x,y] = eulersolve(fh,xspan,y0,h) n = length(y0); % assume column vector x = xspan(1):h:xspan(2); M = length(x); y = zeros(n,M); y(:,1) = y0; xk = xspan(1); for k=1:M-1 yk = y(:,k); y(:,k+1) = yk + h*feval(fh,xk,yk); xk = xk + h; end y = y.’; % matlab convention(see ode23/45)
18
Adaptive StepSizes In some algorithms, called adaptive, the stepsize is –adjusted automatically, –based on the magnitude of f. In this case, the stepsize is written h k and the iteration is More details, as usual, in Math 128A
19
Higher Order Methods (Runge-Kutta) In the Euler method, the approximate solution at the next step is based on evaluating the function f at one point, In Runge-Kutta algorithms, the approximate solution at the next step is based on evaluating the function f at several points. More details, as usual, in Math 128A
20
ode23, ode45 : Runge-Kutta Syntax is [x,y] = ode45(fh,xspan,y0) The input arguments are –fh is a function handle to the function describing the governing equation. Called repeatedly, by ode45, with two arguments, feval(fh,xvalue,yvalue). Should return a column vector representing y´ –xspan, 1-by-2 row vector, [X0 Xfinal] –y0, initial condition, n-by-1 column vector The output arguments are –x, M-by-1 vector of x-values where approx soln is computed –y, M-by-n “solution”. –Approximate solution at x(k) is y(k).’
21
Example: Ordinary Differential Equations Simple example First, write function yp = cclin(x,y) yp = -2*y; Complex example function yp = ncclin(x,y) yp = (-0.75+sin(x))*y; Then >> [xS,yS] = ode45(@cclin,[0 5],1.5); >> [xC,yC] = ode45(@ncclin,[0 10],1.5);
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.