Question

1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N components; l

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab example for Lagrange Interpolation function clear all close all %Example and y for using function p-polyintour as tnamData plotting using Lagrange Interpolation 700 -Actual Data ated data 600 500 400 300 100 1 23456789 10 X value Published wit

%%Matlab example for Lagrange Interpolation function
clear all
close all
%Example for using function p=polyintourastname(x,y,w)
%x and y data values
x1=[1 2 4 5.5 7.5 9 10];
y1=[-6.5 -18.5 -26.5 14 184.5 436.5 679];
%plotting of actual data
plot(x1,y1);
%interpolated data points
w=linspace(1,10,200);
p=lagrangeforminterpolation(7,x1,y1,w);
hold on
%plotting of interpolated data
plot(w,p)
title('Data plotting using Lagrange Interpolation')
xlabel('X value')
ylabel('Y value')
legend('Actual Data','Interpolated data')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%% Matlab function for Lagrange interpolation %%%%%%%%%%
function [value]=lagrangeforminterpolation(N,x,y,z)
    syms xx
    %xi=independent variable;yi=dependent variable;x=value at which we have to
    %find the dependent variable;y=corresponding value of dependent variable at x;
    %loop for creating the Lagrange Interpolation function
        for i=1:N
            s1=1;
            s2=1;
            for j=1:N
                if i~=j
                    s1=(xx-x(j))*s1;
                    s2=(x(i)-x(j))*s2;
                end
             end
             zz(i)=(s1./s2)*y(i);
        end
        f(xx)=sum(zz);
    %interpolated data using Lagrange Method
    for i=1:length(z)
        value(i)=double(f(z(i)));
    end
  
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N comp...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT