1

So I have this function to create a divided difference table but i need to write another function to find the values of the polynomials and i am completely lost as to how to do it.

function [F] = divdiff(x,y)
n=length(x)

F=zeros(n,n)
    
    for i = 1:n
        F(i,1) = y(i)
    end
    
    for j = 2:n
        for i = j:n
            F(i,j) = (F(i,j-1) - F(i-1, j-1))./ (x(i)-x(i-j+1));
        end
    end

now i have `function v = polyvalue(a,x,t)

    pval = zeros(length(t),1);
   for ind_t = 1:length(t);
       t_val = t(ind_t);
       
       for ind_a = 1: length(a)
           xterm_val = 1,
           
           for ind_x = 1:(ind_a - 1)
               xterm_val = xterm_val .* (t_val -x(ind_x));
               pval(ind_t) = pval(ind_t) + a(ind_a) .* xterm_val
           end
       end
   end
   end`

which is not working

  • 2
    Minor nitpick: `i` and `j` represent the [imaginary unit](https://en.wikipedia.org/wiki/Imaginary_unit) in Matlab. Just to avoid confusion when you use complex numbers, you should make it a habit to name your iteration variables ``ii` and `jj` or something else. – Pranav Hosangadi Sep 30 '20 at 18:35
  • What do you mean by 'find the values of the polynomials'? Does it mean you want to interpolate your data with a polynomail `p` and evaluate the value of the polynomial for a given `x`, `p_val = p(x)`? If so, you may check [here](https://www.geeksforgeeks.org/newtons-divided-difference-interpolation-formula/). There is a bunch of examples in different languages, you can see how you change that for MATLAB. – Thales Oct 01 '20 at 15:46

0 Answers0