Solution6

Solution6 - ChE132B HW#6 Solutions (60pt) Problem1 (20pt)...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: ChE132B HW#6 Solutions (60pt) Problem1 (20pt) function [ginf,x,y]=hw61(h0) % define a function to use the shooting method, 5pt n=20; xi=0; xf=10; fi=0; gi=0; hi=h0; yi=[fi;gi;hi]; func=@(x,y) [y(2);y(3);-0.5*y(1)*y(3)]; [x,y]=RungeKuttaM(func,xi,yi,xf,n); ginf = y(2,n+1)-1; function [x,y] = RungeKuttaM(func,xi,yi,xf,n) % 5pt , the multidimensional Runge-Kutta method x=zeros(1,n+1); s=length(yi); y=zeros(s,n+1); p=ones(s,1); x(1)=xi; y(:,1)=yi; h=(xf-xi)/n; for i=1:n x(i+1) = x(i)+h; k1 = feval(func,x(i),y(:,i)); k2 = feval(func,x(i)+0.5*h,y(:,i)+0.5*k1*h.*p); k3 = feval(func,x(i)+0.5*h,y(:,i)+0.5*k2*h.*p); k4 = feval(func,x(i)+h,y(:,i)+k3*h.*p); y(:,i+1) = y(:,i)+(k1+2.*(k2+k3)+k4)*h/6.*p; end % 5pt , the Blasius frictional drag coefficient, Cd. >> Cd=fzero(@hw61, [0.1,1],optimset( 'TolX' ,1e-4)) Cd = 0.3321 % 5pt , plot f, f’, f’’ vs. z. [ginf,x,y]=hw61(Cd); subplot(3,1,1) plot(x,y(1,:)) xlabel( 'z' ) ylabel( 'f(z)' ) subplot(3,1,2) plot(x,y(2,:)) xlabel( 'z' ) ylabel( 'df/dz' ) subplot(3,1,3) plot(x,y(3,:)) xlabel( 'z' ) ylabel( 'd2f/d2z' ) Problem2 (20pt) function [x,y,dy,iter]=hw62(N) % 3pt , Chebyshev differentiation [D,x]= chebD(N); D2 = D^2; x=5*x; % rescale x D2(1,:) = zeros(1,N+1); D2(1,1) = 1.; % for right boundary condition D2(N+1,:) = zeros(1,N+1); D2(N+1,N+1) = 1 ; % for left boundary condition err=1; iter=0;...
View Full Document

This note was uploaded on 02/12/2012 for the course CHE 132b taught by Professor Ceweb during the Fall '09 term at UCSB.

Page1 / 7

Solution6 - ChE132B HW#6 Solutions (60pt) Problem1 (20pt)...

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

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