# hw08_p02 - fid4 = fopen('hw08_p02_answer.txt','a'); % 'wt'...

This preview shows page 1. Sign up to view the full content.

% File name: hw08_p02.m % clc clear x(1) = input('x1: '); y(1) = input('y1: '); h = input('h: '); n = 1; n % int_1 is for making table using 'mod' operator if h == 1/4 int_1 = 1; elseif h == 1/8 int_1 = 2; elseif h == 1/16 int_1 = 4; else int_1 = 1; end e for i = h:h:2 x(n+1) = x(n) + h; y(n+1) = hw08_p02runge(x(n), y(n), h); n = n+1; end e % ytrue = x./(1.0+x.^2); % problem 2(a) ytrue = 1.0/4.0*(3.0*exp(-4.0*x) + 1.0); % problem 2(b) y % open file
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fid4 = fopen('hw08_p02_answer.txt','a'); % 'wt' means &quot;write text&quot; if (fid4 &lt; 0) error('could not open file &quot;hw08_p02_answer.txt&quot;'); end; e fprintf(fid4,'\n\nh = %10.5f\n', h); fprintf(fid4,'x\t\t\t\ty(x)\t\t\t\tY(x)\t\t\t\terror\n'); for i = 1:length(x) if mod(i-1,int_1) == 0 fprintf(fid4,'%15.5f%15.5f%15.5f%15.5f\n', . .. x(i),y(i),ytrue(i), y(i)-ytrue(i)); end end fclose(fid4);...
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 at Austin.

Ask a homework question - tutors are online