# hw10_p04 - end diff(n) = Y1(length(x),n) - yend; end e %...

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

clc clear c D = input('D: '); K = input('K: '); h = input('h: '); xstart = input('x_min: '); xend = input('x_max: '); ystart = input('y at x_min: '); yend = input('y at x_max: '); tolerance = input('Tolerance: '); % int_1 is for making table using 'mod' operator int_1 = 1; p_initial = input('1 st initial guess: '); x=xstart:h:xend; n = 1; Y1(1,n) = ystart; Y2(1,n) = p_initial; Y for i=2:length(x) [Y1(i,n), Y2(i,n)] = hw10_p04RK4(h,x(i-1),Y1(i-1,n),Y2(i-1,n),K,D); % RK4 end e diff(n) = Y1(length(x),n) - yend; d p_initial = input('2 nd initial guess: '); p n=n+1; n Y1(1,n) = ystart; Y2(1,n) = p_initial; Y for i=2:length(x) [Y1(i,n), Y2(i,n)] = hw10_p04RK4(h,x(i-1),Y1(i-1,n),Y2(i-1,n),K,D); % RK4 end e diff(n) = Y1(length(x),n) - yend; d while ( abs( Y2(1,n) - Y2(1,n-1) ) > tolerance ) p_initial = Y2(1,n) - diff(n)*( Y2(1,n) - Y2(1,n-1) )/( diff(n) - diff(n-1) ); n=n+1; Y1(1,n) = ystart; Y2(1,n) = p_initial; for i=2:length(x) [Y1(i,n), Y2(i,n)] = hw10_p04RK4(h,x(i-1),Y1(i-1,n),Y2(i-1,n),K,D); % RK4

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: end diff(n) = Y1(length(x),n) - yend; end e % open file fid4 = fopen('hw10_p04_answer.txt','a'); % 'wt' means "write text" if (fid4 < 0) error('could not open file "hw09_p04_answer.txt"'); end; fprintf(fid4,'\n\nh = %10.5f\tTolerance = %10.7f\n', h, tolerance); fprintf(fid4,'y(%10.5f)=%10.5f, y(%10.5f)=%10.5f\n', xstart, ystart, xend, yend); fprintf(fid4,'1 st guess = %10.5f, 2 nd guess = %10.5f\n', Y2(1,1), Y2(1,2)); fprintf(fid4,'\t\t\tx\t\t\t\tY1(x)\n'); fprintf(fid4,'iter'); for j = 1:n fprintf(fid4,'%10d',j); end fprintf(fid4,'\n'); for i = 1:length(x) if mod(i-1,int_1) == 0 fprintf(fid4,'%10.5f',x(i)); for j = 1:n fprintf(fid4,'%10.5f', Y1(i,j)); end fprintf(fid4,'\n'); end end fclose(fid4); f figure(1), plot(x,Y1(:,n),'o',x,Y1(:,n)) xlabel('x (cm)'); ylabel('Concentraion (M)'); legend('C_A'); title('Problem 04 in HW#10: figure');...
View Full Document

## This note was uploaded on 02/22/2010 for the course CHE 348 taught by Professor Chelikowsky during the Spring '08 term at University of Texas.

### Page1 / 2

hw10_p04 - end diff(n) = Y1(length(x),n) - yend; end e %...

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

View Full Document
Ask a homework question - tutors are online