﻿disp("#Q2");

x = [0, 1, 2];
f=@(x) exp(x);
y=[f(0), f(1), f(2)];

result1a = DannyNewtonInterp(x, y)

disp("#Q3");

x = [0.1, 0.2, 0.3, 0.4, 0.5];
y = [0.12, 0.14, 0.13, 0.15, 0.11];

result3a = DannyNewtonInterp(x(1:4), y(1:4))(1,1:4)
result3b = DannyNewtonInterp(x(1:5), y(1:5))(1:5,1:5)

disp("#Q4 ");

x = [1,2,3,4];
y = [2,2,0,0];

result4 = DannyNewtonInterp(x(1:4), y(1:4))(1,1:4)

disp("#Q5");

x = [0,30,1029];
y = [10,58,-32];

result5 = DannyNewtonInterp(x, y)

disp("#Q6");
x = [1,2.2,3];
y = [0.987,-0.123,0.432];

result6 = DannyNewtonInterp(x, y)

disp("#Q7 to double check, and jsut maybe a teensy bit more :>");

x = [1.2,1.4,1.6];
y = [2.2,2.1,2.3];

result7 = DannyNewtonInterp(x, y)

disp("#Q8");

x = [1,2,3,4];
y = [1,3,5,7];

result8 = DannyNewtonInterp(x, y)

disp("#Q9");

x = [2,3,4];
y = [3,5,4];

result9 = DannyNewtonInterp(x, y)

disp("#Q10");

x = [0,0.1,0.3,0.6,1.0,1.1];
y = [-6,-5.89483,-5.65014,-5.17788,-4.28172,-3.9958];

result10a = DannyNewtonInterp(x(1:5), y(1:5))
result10b = DannyNewtonInterp(x(1:6), y(1:6))


disp("#Q11 Similar to question 10, as I demonstrated, once we have the a values the polynomial can be algorithmacly found, code below to find the a's and compute the values for said polynomials using neviles method");

x = [8.1,8.3,8.6,8.7];
y = [16.94410,17.56492,18.50515,18.82091];
xhat = 8.4;


result11a = DannyNewtonInterp(x(2:3), y(2:3))
result11ab = DannyNeviles(xhat, x(2:3), y(2:3))(1,2)

result11b = DannyNewtonInterp(x(2:4), y(2:4))
result11bb = DannyNeviles(xhat, x(2:4), y(2:4))(1,3)

result11c = DannyNewtonInterp(x, y)
result11cb = DannyNeviles(xhat, x, y)(1,4)


