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

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

  • Problem 2. Given the data points (xi. yi), with xi 2 02 4 yil 5 1 1.25 find the following interpo...

    Problem 2. Given the data points (xi. yi), with xi 2 02 4 yil 5 1 1.25 find the following interpolating polynomials, and use MATLAB to graph both the interpolating polynomials and the data points: a) The piecewise linear Lagrange interpolating polynomialx) b) The piecewise quadratic Lagrange interpolating polynomial q(x) c) Newton's divided difference interpolation pa(x) of degree s 4 Problem 2. Given the data points (xi. yi), with xi 2 02 4 yil 5 1 1.25 find the following...

  • (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 wit...

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

  • need help doing this in matlab. 1.2-1.4 Problem #1. For five data points listed in Table...

    need help doing this in matlab. 1.2-1.4 Problem #1. For five data points listed in Table 1, you are asked to do the following: Write down the form of a Newton's interpolating polynomial function of 4th-order with five constants (b, i = 1:5). 1.2 Calculate the following three divided differences (Newton bracket) (showing the detailed steps and numbers on a white paper): [xy, x,]= [xx, x,]= S[X2, x3, x,]= Plot both the data points and the interpolating function by using...

  • 4. (25 pts) Given a function f with three continious derivatives, and three equally spaced points...

    Parts b and c please 4. (25 pts) Given a function f with three continious derivatives, and three equally spaced points zi z, = zi+h, エ3年エ1 + 21, we would like to approxinate f'(z), Let p(z) be the quadratic polynomial interpolating ()) (a) Write p in the Lagrange form. (b) Show the forward difference formula (c) Prove that this expression is a second order approximation off,(r), that is, show that where C depends on the third derivative of f. 4....

  • 3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 point...

    3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 points of this function: 10.5403 2 -0.4161 6 0.9602 (a) (2 points) Calculate the quadratic Lagrange interpolating polynomial as the sum of the Lo(x), L1(x), L2(x) polynomials we defined in class. The final answer should be in the form P)a2 bx c, but with a, b, c known. DELIVERABLES: All your work in constructing the polynomial. This is to be done by hand...

  • 8. Write a MATLAB function that will take as inputs a set of data (x,y) and...

    8. Write a MATLAB function that will take as inputs a set of data (x,y) and output the best estimate of the integral using a Romberg Array. The function should perform two trapezoidal integrations using the full interval and half the interval, and then combine these integrations in a Romberg Array. Your function should also output the relative error of the integral. Please note that the data entered may not be evenly spaced and your function should make sure that...

  • Write a Matlab function called sine_Taylor that inputs a positive integer n, a number x, and...

    Write a Matlab function called sine_Taylor that inputs a positive integer n, a number x, and outputs the nth Taylor polynomial of the sine function. Compute the absolute and error for n = 1: 10 at x = 1, obtained by comparing the output of your function to that of Matlab's built in sine function. Type on the Matlab console format long, then compute the previous error. Repeat the operation by typing format short. Comment on the result (quantify the...

  • - Question 5 1 point Number Help Given data points (x;, Y;) for j= 0,...,9, the...

    - Question 5 1 point Number Help Given data points (x;, Y;) for j= 0,...,9, the degree of the Lagrange polynomial L3(x) is Number I

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