Question

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

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

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...!!

Add a comment
Know the answer?
Add Answer to:
1. (25 pts) Write a Matlab function with the header function [value- polynomialpiece(m,x.y,k,z) that inputs number of d...
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