hw08_p06b

# hw08_p06b - File name hw08_p06b.m RK4 and AB4-AM4 for a...

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

% File name: hw08_p06b.m % RK4 and AB4-AM4 for a linear system % Written by Jason Kenny and modified by Sangheon Lee clc clear c 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 %from part (a): for i=2:4 [Y1(i), Y2(i), Y3(i)] = hw08_p06RK4(h,x(i-1),Y1(i-1),Y2(i-1),Y3(i-1)); end e %Get fprime values for the points already calculated: for i=1:4 fprime1(i) = Y2(i); fprime2(i) = Y3(i); fprime3(i) = -4.0*Y3(i) - 5.0*Y2(i) - 2.0*Y1(i) + 2.0*x(i)^2 + 10.0*x(i) + 8.0; end e for i=5:length(x) %AB4 predictor. We'll store these predictions in the Y arrays, then %overwrite them with the corrected values later: [Y1(i) Y2(i) Y3(i)] = hw08_p06AB4(i,h,Y1(i-1),Y2(i-1),Y3(i- 1),fprime1,fprime2,fprime3); %We'll store the estimates for the fprime values at the current point

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern