hw08_p06a - %from part(a for i=2:length(x[Y1(i Y2(i Y3(i =...

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

View Full Document Right Arrow Icon
% File name: hw08_p06a.m % RK4 and AB4-AM4 for a linear system % Written by Jason Kenny and modified by Sangheon Lee clc clear xmin = input('x_min: '); xmax = input('x_max: '); x(1) = input('x1: '); Y1(1) = input('Y1_1: '); Y2(1) = input('Y2_1: '); Y3(1) = input('y3_1: '); Y h = input('h: '); h % 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 x=xmin:h:xmax; x %We need to get a total of 4 starting values for AB4-AM4, so we use RK4 to %get the next 3 after the initial (given) value. Recycling the function
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %from part (a): for i=2:length(x) [Y1(i), Y2(i), Y3(i)] = hw08_p06RK4(h,x(i-1),Y1(i-1),Y2(i-1),Y3(i-1)); end e Y1true = exp(-x) + x.^2; Y % open file fid4 = fopen('hw08_p06_answer.txt','a'); % 'wt' means "write text" if (fid4 < 0) error('could not open file "hw08_p06_answer.txt"'); end; fprintf(fid4,'\n\nh = %10.5f\n', h); fprintf(fid4,'x\t\t\t\tY1(x)\t\t\tY1_true(x)\t\t\t\terror\n'); for i = 1:length(x) if mod(i-1,int_1) == 0 fprintf(fid4,'%15.8f%15.8f%15.8f%15.8f\n', . .. x(i),Y1(i),Y1true(i), Y1(i)-Y1true(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.

Ask a homework question - tutors are online