

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


format long xi = linspace(0, 10, 6); for k=1: ai(k) = divided_difference(@cos, xi(1:k)); end actual = cos([pi/3 pi/2 pi]); approx = newton_eval([pi/3 pi/2 pi], ai, xi)
approx =
0.694083092853490 0.067661126195064 -1.
abserr = abs(actual - approx)
abserr =
0.194083092853490 0.067661126195064 0. The command “format long” tells MATLAB to print more decimal digits than the default number (5). The last two calculations were printed because they weren’t followed by semicolons.
xdata = linspace(0, 10); ydata1 = newton_eval(xdata, ai, xi); ydata2 = cos(xdata); plot(xdata, ydata1, xdata, ydata2) These commands produce figure 1 when run in MATLAB and figure 2 when run in Octave. (The figure can be saved to disk using a command like “print -dpdf pa1graph”.)
Date: Due Monday 7/20. 1
Figure 1. Graph from problem 3 (MATLAB)
Figure 2. Graph from problem 3 (Octave)
-1.
-0.
0
1
0 2 4 6 8 10 2