E7 Assignment 9 Solutions

E7 Assignment 9 Solutions - E7 Assignment 9 Solutions...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
E7 Assignment 9 Solutions Summer 2010 Contents Problem 1 Problem 2 Problem 3 Problem 4 (a) (b) (c) (d) Problem 5 (a) (b) (c) Problem 6 Problem 7 Problem 8 Problem 9 (a) (b) Problem 10 Problem 11 (a) (b) (c) Problem 12 (a) (b) (c) (d) (i) (ii) (iii) (iv) (v) Problem 1 type createFDD
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
function [forward,backward,centered] = createFDD(fh,h) forward = @(x) ( fh(x+h) - fh(x) ) / h; backward = @(x) ( fh(x) - fh(x-h) ) / h; centered = @(x) ( fh(x+h) - fh(x-h) ) / (2*h); Test the finite difference approximations visually. fh = @(x) sin(2*x); [df,db,dc] = createFDD(fh,.05); x = linspace(0,pi,200); plot(x,df(x), 'r' ,x,db(x), 'g' ,x,dc(x), 'k' ,x,2*cos(2*x), 'c' ); It's optional, but this plot would be much better with a legend and title legend( 'Forward' , 'Backward' , 'Centered' , 'Exact' , 'Location' , 'best' ) title( 'Approximations to the derivative' )
Background image of page 2
Problem 2 k = 0.026; P0 = 2555; Pmax = 12000; tspan = 1950:5:2050; f = @(t,p)( k*(1-p/Pmax)*p ); [t,P] = ode45(f,tspan,P0); Pexact = P0*Pmax ./ ( P0 + (Pmax-P0)*exp( -k*(t-tspan(1)) ) ); plot(t,P, 'r.-' ,t,Pexact, 'b--' ); xlabel( 'Year' ); ylabel( 'Population (millions)' ); legend( 'Numerical Soln' , 'Exact Soln' , 'Location' , 'best' );
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problem 3 Convert two coupled 1-dimensional ODEs to a single 2-dimensional ODE by defining w = [y;z]. f = @(t,w)( [ -2*w(1)+4*exp(-t); -w(1)*w(2)^2/3 ] ); w0 = [2;4]; tspan = 0:0.1:4; [t,w] = ode45(f,tspan,w0); y = w(:,1); z = w(:,2); plot(t,y,t,z); xlabel( 'Time, t' ); ylabel( 'y(t) and z(t)' ); legend( 'y(t)' , 'z(t)' , 'Location' , 'best' );
Background image of page 4
Problem 4 (a) type LorenzODE function dY = LorenzODE(Y,sigma,beta,rho) dY = zeros(size(Y)); dY(1) = sigma*( Y(2)-Y(1) ); dY(2) = Y(1)*( rho-Y(3) ) - Y(2); dY(3) = Y(1)*Y(2) - beta*Y(3); (b) sigma = 10; beta = 8/3; rho = 14; Lorenz = @(t,y)( LorenzODE(y,sigma,beta,rho) ); tspan = [0,20]; Y0 = { [0;1;1] [1;1;1] [1;-1;1] [1;-1;-1] [1;-1;-10] }; color = { 'b' , 'g' , 'r' , 'c' , 'm' }; figure t = cell(1,5); Y = cell(1,5); for k = 1:length(Y0)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
[t{k},Y{k}] = ode45(Lorenz,tspan,Y0{k}); plot3(Y{k}(:,1),Y{k}(:,2),Y{k}(:,3),color{k}); hold on end view(0,0); All of the initial conditions result in trajectories that converge to spiral paths. The interesting thing is that some paths that start on the left move to the spiral on the right and vice versa. (c) sigma = 10; beta = 8/3; rho = 28; Lorenz = @(t,y)( LorenzODE(y,sigma,beta,rho) ); tspan = [0,20]; Y0 = { [0;1;1] [0.001;1;1] }; color = { 'b' , 'g' , 'r' , 'c' , 'm' }; figure t = cell(1,2); Y = cell(1,2); for k = 1:length(Y0) [t{k},Y{k}] = ode45(Lorenz,tspan,Y0{k}); plot3(Y{k}(:,1),Y{k}(:,2),Y{k}(:,3),color{k}); hold on end
Background image of page 6
view(0,0); In this case, the trajectories make multiple orbits in both of the spirals (d) tspan = [0,50]; figure t = cell(1,2); Y = cell(1,2); for k = 1:length(Y0) [t{k},Y{k}] = ode45(Lorenz,tspan,Y0{k}); plot3(Y{k}(:,1),Y{k}(:,2),Y{k}(:,3),color{k}); hold on end view(0,0);
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/14/2010 for the course E 7 taught by Professor Patzek during the Summer '08 term at University of California, Berkeley.

Page1 / 28

E7 Assignment 9 Solutions - E7 Assignment 9 Solutions...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online