Question

1. (25 pts) Given integer N > 0; vector r of distinct nodes with N components, ordered from smallest to largest; vector y of
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%%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 %%%%%%%%%%%%%%

Data plotting using Lagrange Interpolation 700 Actual Data Interpolated data 600 500 400 300 200 100 -100 10 5 K value Publis

Add a comment
Know the answer?
Add Answer to:
1. (25 pts) Given integer N > 0; vector r of distinct nodes with N components,...
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
  • 1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N comp...

    1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N components; location 2 complete the Matlab function with header function [valuelagrangeforminterpolation(N,x,yz) so that it uses the Lagrange form to output the value of the Lagrange interpolating polynomial at Remember Lagrange form: 1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N components; location 2 complete the...

  • 1. (25 pts) Write a Matlab function with the header function [value- polynomialpiece(m,x.y,k,z) that inputs number of d...

    1. (25 pts) Write a Matlab function with the header function [value- polynomialpiece(m,x.y,k,z) that inputs number of data points m; vectors a and y, both with m components, holding r- and y-coordinates, respec- tively, of data points, and where the components of r are evenly spaced and in increasing order (rk/2,z,n+1-k/2) an even number k and a location distinct from the 0, > z . nodes; and outputs, using Lagrange form, the value at z of the deg S k-1...

  • 3. For any function f and n1 distinct nodes ro,....Tn, Lagrange interpolation factors f P R where...

    3. For any function f and n1 distinct nodes ro,....Tn, Lagrange interpolation factors f P R where and R is the approximation error. The following Matlab function, function a linterp_poly (X, a-zeros (1,numel(X)) for i1:numel(X) aa - poly (X([1:i-1 i+1:end])); a-a + Y(i) * aa / polyval (aa, X(i)); end end represents P(z)-Ση:0akrk as its coefficients a-lan, an-1, , al, ao (this solves Worksheet 7 Q2.) a) Write a Matlab function that uses P to approximate fd() for any positive...

  • 1. (25 pts) Let f(x) be a continuous function and suppose we are already given the Matlab function "f.", with header "function y fx)", that returns values of f(x) Given the following...

    1. (25 pts) Let f(x) be a continuous function and suppose we are already given the Matlab function "f.", with header "function y fx)", that returns values of f(x) Given the following header for a Matlab function: function [pN] falseposition(c,d,N) complete the function so that it outputs the approximation pN, of the method of false position, using initial guesses po c,pd. You may assume c<d and f(x) has different signs at c and d, however, make sure your program uses...

  • The Taylor polynomial approximation pn (r) for f(x) = sin(x) around x,-0 is given as follows: TL ...

    The Taylor polynomial approximation pn (r) for f(x) = sin(x) around x,-0 is given as follows: TL 2k 1)! Write a MATLAB function taylor sin.m to approximate the sine function. The function should have the following header: function [p] = taylor-sin(x, n) where x is the input vector, scalar n indicates the order of the Taylor polynomials, and output vector p has the values of the polynomial. Remember to give the function a description and call format. in your script,...

  • 2. Discrete Fourier Transform.(/25) 1. N-th roots of unity are defined as solutions to the equation:...

    2. Discrete Fourier Transform.(/25) 1. N-th roots of unity are defined as solutions to the equation: w = 1. There are exactly N distinct N-th roots of unity. Let w be a primitive root of unity, for example w = exp(2 i/N). Show the following: N, if N divides m k=0 10, otherwise N -1 N wmk 2. Fix and integer N > 2. Let f = (f(0), ..., f(N − 1)) a vector (func- tion) f : [N] →...

  • Task The task for this assignment is to have the following user-defined data type: struct rgb...

    Task The task for this assignment is to have the following user-defined data type: struct rgb { unsigned char red; unsigned char green; unsigned char blue; }; be able to be: read in from a stream (e.g., std::cin), i.e., write: std::istream& operator >>(std::istream& is, rgb& colour); (see below) written out to a stream (e.g., std::cout), i.e., write: std::ostream& operator <<(std::ostream& os, rgb const& colour); (see below) stored in a container, e.g., std::vector<rgb>, std::array<rgb,16>; (see below) processed via algorithms (and other...

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