Lagrange interpolation-question on the logic
1 ビュー (過去 30 日間)
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
fx=y(i); % Putting ith value as function value
if i ~= j
fx= fx*(xx-x(j))/(x(i)-x(j)) % Calculating the products
sum =sum+fx; % Adding fx values
calculated_value = sum;
回答 (1 件)
Torsten 2015 年 5 月 21 日
First you must build the complete product, then you can add.
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!