hw07_p04 - y % open file fid4 =...

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

View Full Document Right Arrow Icon
% File: hw07_p04.m % Function file: hw07_p04trap.m % Written by Jason Kenny and modified by Sangheon Lee clc clear x(1) = input('x1: '); y(1) = input('y1: '); h = input('h: '); n = 1; % 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; [ypred(n+1),y(n+1)] = hw07_p04trap( x(n), y(n), h); n=n+1; end e ytrue = x./(1+x.^2);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y % open file fid4 = fopen('hw07_p04_answer.txt','a'); % 'wt' means "write text" if (fid4 < 0) error('could not open file "hw07_p04_answer.txt"'); 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

Ask a homework question - tutors are online