%%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 %%%%%%%%%%%%%%
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 r of distinct nodes with N components, ordered from smallest to largest; vector y of nonzero values at nodes with N components suppose the piecewise linear interpolant P(x) of this data has a root. Complete the Matlab function with header function [root] linearinterpolationroot(N,x.y) so that it outputs the smallest root of P(r). Remember, the piecewise linear interpolant is only defined between the smallest and largest nodes. 1. (25 pts) Given integer...
1. (25 pts) Given the following start for a Matlab function: function [answer] = NewtonForm(m,x,y,z) that inputs • number of data points m; • vectors x and y, both with m components, holding x- and y-coordinates, respectively, of data points; • location z; and uses divided difference tables and Newton form to output the value of the Lagrange polynomial, interpolating the data points, at z. 1. (25 pts) Given the following start for a Matlab function: function [answer] NewtonForm(m.x.yz) that...
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...
Compute, using divided differences, the value of the piecewise cubic Her- mite interpolating polynomial at x = 11=10 given nodes at xi = i, for i = 1; : : : ; 10, and values and derivatives at the nodes from the function f(x) = 1=x. Remember iterative formula for divided differences: 2. (25 pts) Compute, using divided differences, the value of the piecewise cubic Her mite interpolating polynomial at x-11/10 given nodes at ai-i, for i-1, , 10. and...
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...
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...
7. (15 pts) Numerical Integration. Given a continuous function f (x) on the interval [a, b], write the Lagrange form of the quadratic polynomial interpolating f(a), (a b)), f(b). Instead of calculating the integral I(f) Jaf(x)dx we could approximate it via Q(f) = | q(x)dx. Find an expression for this quadrature rule, the so-called Simpson's rule.
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,...
1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...
please help me solve part (c). 2,U2 1, x2 = 2 and yo = 0,31 0 3. Given the data x0 y for the polyno- a) (15 pts) Set up the Vandermonde system Vc mial interpolant p(x) = co + C1x + c2x2 such that p(zi) = yi, 2 0,1,2 b) (15 pts) Find the solution of the system and sketch y px) c) (15 pts) Write down the Lagrange form of the interpolating poly- nomial and simplify the result....