ShootingMethod - function ShootingMethod % Simple Matlab...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 function ShootingMethod % Simple Matlab program to demonstrated the shooting method % with the heat transfer example problem used in lecture. % The differential equation for this problem is % d^2T/dx^2 + h(Ta - T) = 0 % with x = 0 to 10, Ta = 20, and boundary conditions % T(0) = 40 and T(10) = 200. % First convert the second order ODE into two first order ODEs % dT/dx = z (first derivative of original variable = new variable) % dz/dx = d^2T/dx^2 = - h(Ta - T) % The state vector y is then % y = [T z] % and the state derivative vector is % dy/dx = [dT/dx dz/dx] % For the shooting method, guess dT/dx(0), see if it gives the % correct T(10) value, and then iterate until converged % Approach 1: Iterate manually 5 times T0 = 40 T10 = 200 npts = 101 xspan = linspace(0,10,101) for i = 1:5 z0 = input('\nEnter a guess for dT/dx(0): ') y0 = [T0 z0]' [x,y] = ode45(@HeatTransfer,xspan,y0) T = y(:,1) fprintf('The final value of T is %5.2f\n', T(npts)) end fprintf('The final guess for dT/dx(0) was %5.2f\n', z0)
Background image of page 1

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

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

Page1 / 2

ShootingMethod - function ShootingMethod % Simple Matlab...

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

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