IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE TTHERE TO HELP YOU..ALL THE BEST..
AS FOR GIVEN DATA.
MATLAB:
%%Matlab example for Lagrange Interpolation
function
clear all
close all
%Example for using function
[value]=polynomialpiece(m,x,y,k,z)
m=100;
x1=linspace(-5,5,m);
y1=x1.^2;
%plotting of actual data
plot(x1,y1);
%interpolated data points
k=10;
z=linspace(-3,0,k);
p=polynomialpiece(m,x1,y1,10,z);
hold on
%plotting of interpolated data
plot(z,p,'linewidth',2)
title('Data plotting using Lagrange Interpolation')
xlabel('X value')
ylabel('Y value')
legend('Actual Data','Interpolated data')
%%%%%%%%%% Matlab function for Lagrange
interpolation %%%%%%%%%%
function [value]=polynomialpiece(m,x,y,k,z)
%Data points colses to z
for i=1:k
%finding data points
close to z
c=abs(x-z(i));
[bb,ii]=sort(c);
x1(i)=x(ii(1));
y1(i)=y(ii(1));
end
syms xx
%loop for creating the Lagrange Interpolation
function
for i=1:k
s1=1;
s2=1;
for j=1:k
if i~=j
s1=(xx-x1(j))*s1;
s2=(x1(i)-x1(j))*s2;
end
end
zz(i)=(s1./s2)*y1(i);
end
f(xx)=sum(zz);
%interpolated data using Lagrange Method
for i=1:k
value(i)=double(f(x1(i)));
end
end
I HOPE YOU UNDERSTAND..
PLS RATE THUMBS UP..ITS HELPS ME ALOT..
THANK YOU...!!
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) 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...
(Matlab) Suppose we have a function “hw5f.m” that takes as input x and outputs the value for a function f(x). Write a Matlab program that inputs: • interval [a, b]; • m, the number of data points with evenly spaced nodes from x1 = a to xm = b, and values from f(x); • location z satisfying x2 < z < xm−1, where h = (b − a)/(m − 1); and outputs the value of the interpolaton polynomial using only...
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...