% Problem 1 of HW 18 clear load hw17.dat x = hw17(:,1); y = hw17(:,2); S = spline(x,y); xstar = input('input xstar: '); ystar = ppval(S,xstar); ye = 1 + xstar^2*cos(xstar)*sin(xstar); ae = abs(ystar - ye); re = ae/abs(ye) %>> hw18_1 %input xstar: 0.01 %re = % 1.510766196203829e-05 %>> hw18_1 %input xstar: 1.4 %re = % 3.443301054427209e-05 %>> hw18_1 %input xstar: 3.1 %re = % 7.152931648681873e-04 ----------------------------------------- % Problem 2 of HW 18 clear load hw18.dat x = hw18(:,1); y = hw18(:,2); S = spline(y,x); ystar = input('input ystar: '); xstar = ppval(S,ystar); xe = asin(ystar); ae = abs(xstar - xe); re = ae/abs(xe) % NOTE: These relative errors are not as good because the x coordinates (which % are irrational numbers) are only given to 3 digits. % >> hw18_2 % input ystar: .30 % re = % 1.313072037866159e-02 % >> hw18_2 % input ystar: 0.75 % re = % 3.988992411297724e-03 % >> hw18_2 % input ystar: 0.91 % re = % 9.645308830142585e-03 -------------------------------------------- % Problem 3 of HW 18 For this problem two approaches would be: * Take the half of the table up to the maximum y value (call this half xh, yh). Use the inverse interpolation technique from Problem 2 with this half of the table; fit a spline using S = spline(yh,xh) * Do a search on y to find out which y values bracket the smallest of the x* values, then use the approach in Problem 2 of HW 17, but fit a cubic to the x values instead of the y-values.