Question

1. (25 pts) Given the following start for a Matlab function: function [answer] NewtonForm(m.x.yz) that inputs » number of dat1. (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.

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


clear all close all %x and y values for finding the %function for which interpolation have to do func-e (x) 1./(1+25.x.*2); xloop for creating the function n-length (z); for i=1:n s1-1; for j= 1 i s1-(x-x1)) s1 end end f_newton (x)-sum(2z1) tyl(l) Va

clear all
close all
%x and y values for finding the
%function for which interpolation have to do
func=@(x) 1./(1+25.*x.^2);
x1=linspace(-1,1,21);
y1=func(x1);

%all interpolating points
z1=linspace(-1,1,101);

%displaying the function
fprintf('The function is f(x)=\n')
disp(func)

%Function for Newton Divide difference
[Value]=NewtonForm(21,x1,y1,z1);


figure(1)
scatter(x1,y1,'filled','Linewidth',2)
hold on
plot(z1,Value,'r')

xlabel('x')
ylabel('f(x)')
title('x vs. f(x) plot')
legend('Actual data','Interpolating data')

%Function for Newton Divided difference interpolation
function [Value]=NewtonForm(m,x1,y1,z1)
  
    %Creatin the Newton Divided difference formulae for variable x
    syms x
    y2=y1;
    zz=zeros(m,m+1);

    zz(:,1)=x1'; zz(:,2)=y1';

    for i=1:m-1

        n1=length(y2);
        for j=1:n1-1
            y3(j)=(y2(j+1)-y2(j))/(x1(i+j)-x1(j));
            zz(j,i+2)=y3(j);
        end
        z(i)=y3(1);
        y2=y3;
        clear y3;
    end

    nn=length(zz);

    %loop for creating the function

    n=length(z);
        for i=1:n
            s1=1;
            for j=1:i
                    s1=(x-x1(j))*s1;
             end
             zz1(i)=(s1)*z(i);
        end
    f_newton(x)=sum(zz1)+y1(1);
    Value=double(f_newton(z1));
  
end

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

Add a comment
Know the answer?
Add Answer to:
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-...
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