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

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

View Full Document Right Arrow Icon
% 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
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern