Lagrange interpolation-question on the logic
    2 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
The following code for calculating the Lagrange interpolation is working, but I have a question: why have we placed the sum after the j-counter not before it ends? wouldn't the fx for the same i and different j overwrite?
Here is the code-I hope it's readable now-:
    % function calculated_value = Lagrange (x,y,xx)
n = length(x);  % Total number of values in x matrix
sum=0; % Initial summation gues
for i=1:n
fx=y(i); % Putting ith value as function value
for j=1:n
  if i ~= j
    fx= fx*(xx-x(j))/(x(i)-x(j)) % Calculating the products
    end
    % end
 sum =sum+fx; % Adding fx values
end
calculated_value = sum;
0 Commenti
Risposte (1)
  Torsten
      
      
 il 21 Mag 2015
        First you must build the complete product, then you can add.
Best wishes
Torsten.
0 Commenti
Vedere anche
Categorie
				Scopri di più su Interpolation in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

