Question

In: Advanced Math

In this problem, you can use the Matlab program posted on course website and Canvas (also...

  1. In this problem, you can use the Matlab program posted on course website and Canvas (also given in the lecture) that computes the interpolation polynomial. We want to see how well a given function can be approximated by the interpolation polynomials. Let f be a function. We divide the the interval [−0.6,0.6] into subintervals of the same length h = 0.02. The gridpoints are −0.6 = x1 < x2 < ... < x61 = 0.6. Take N = 61 points (x1,y1),...(xN,yN) on the graph of f.

    1. (a) For f(x) = sinx, plot the graph of the interpolation P on the interval [−0.6,0.6]. Plot f and all of P on the same graph (for example, by using the command hold on). Does the interpolation polynomial approximate well the function f on the interval [−0.6, 0.6]?

    2. (b) The same questions as in Part (a) but for f (x) = 1+x .

    3. (c) We know that the error between f and P is estimated by

| f (x) − P (x)| ≤ max |f (n) | (∗)

n n−1 [a,b]
Let f (x) = 1 and [a, b] = [−0.6, 0.6]. Use Stirling approximation m√m! ≈ 1 (for large

1+x me m) to show that the right hand side of (∗) goes to infinity as n → ∞.

Solutions

Expert Solution


clear all
close all
%x and y values for finding the
%function for which interpolation have to do
func=@(x)sin(x);
fprintf('function for which interpolation have to do f(x)=')
disp(func)
%all interpolating points
z1=-0.6:0.002:0.6;
figure(1)
hold on
plot(z1,func(z1));
hold on
%all node value
fprintf('\n')
  
    x2=-0.6:0.02:0.6;
    y2=func(x2);
    %Function for Newton Divide difference
    [Value]=NewtonForm(length(x2),x2,y2,z1);
    zz=func(z1);
    err=zz-Value;
    err_max=max(err);
    err_min=min(err);
    err_rs=sqrt(mean((zz - Value).^2));
    fprintf('For n=%d with given data point for sin(x)\n',length(x2))
    fprintf('\tMaximum error = %f\n',err_max)
    fprintf('\tMinimum error = %f\n',err_min)
    fprintf('\tRMSE error = %f\n',err_rs)
    figure(1)
    plot(z1,Value)
    figure(1)
    xlabel('x')
    ylabel('f(x)')
    title('Actual and Newton Interpolation')
    legend('Actual data','Interpolation','location','best')
    box on; grid on
clear all  
%function for which interpolation have to do
func=@(x) 1+x;
fprintf('function for which interpolation have to do f(x)=')
disp(func)
%all interpolating points
z1=-0.6:0.002:0.6;
figure(2)
hold on
plot(z1,func(z1));
%all node value
fprintf('\n')
  
    x2=-0.6:0.02:0.6;
    y2=func(x2);
    %Function for Newton Divide difference
    [Value]=NewtonForm(length(x2),x2,y2,z1);
    zz=func(z1);
    err=zz-Value;
    err_max=max(err);
    err_min=min(err);
    err_rs=sqrt(mean((zz - Value).^2));
    fprintf('For n=%d with given data point for 1+x\n',length(x2))
    fprintf('\tMaximum error = %f\n',err_max)
    fprintf('\tMinimum error = %f\n',err_min)
    fprintf('\tRMSE error = %f\n',err_rs)
    figure(2)
    plot(z1,Value)
    xlabel('x')
    ylabel('f(x)')
    title('Actual and Newton Interpolation')
    legend('Actual data','Interpolation','location','best')
    box on; grid on
%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 %%%%%%%%%%%%%%


Related Solutions

Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem...
Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandstop filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce the below is the Problem 1 initail code .. you can use it Matlab The following cilab code generates a 10-second “chirp”...
Write a case you can use PCR to solve the problem and also write a case...
Write a case you can use PCR to solve the problem and also write a case you cannot use PCR to solve to problem
You can access the Santam Group website and also have a look at their subsidiaries or...
You can access the Santam Group website and also have a look at their subsidiaries or business units like MiWy Insurance, Santam RE, Santam Personal, Santam Specialists, Santam Commercial Question A company pursuing a differentiation strategy strives to create a product or service that customers perceive as being different in some important way. Customers need to believe that the product or service offered has differentiated qualities that are worth paying a premium price for. Provide practical strategic recommendations for how...
Program a solver for the Towers of Hanoi problem presented below. Submit the following to canvas:...
Program a solver for the Towers of Hanoi problem presented below. Submit the following to canvas: Hanoi.java, Driver.java (contains your main method). This is an individual project. Students may discuss solutions to the problem but may not share code with one another. I will discuss this project during our next lecture. Rules: a) There are three Pillars (Pillar1, Pillar2, Pillar3). b) There are N number of disks of increasing size (disk size is indicated by an integer). c) At the...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Use MATLAB to figure out the following problem, if you do not know how to use...
Use MATLAB to figure out the following problem, if you do not know how to use MATLAB then please do not answer. Coding is required for the exercise. For f(x) = arctan(x), find its zeros by implimenting Newtons method and the Secant method in Matlab. (Hint: Use Newtons method to calculate x1 for Secant method) Comment all code please since I would like to learn how to do this correctly in MATLAB. Thank you.
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted...
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted and use your variable names and testArrays.  
Create a Matlab program that can evaluate Green Theorem
Create a Matlab program that can evaluate Green Theorem
Explain how you can use social media to test you website?
Explain how you can use social media to test you website?
Can anyone assist me with the following problem posted below? I just need some simple use...
Can anyone assist me with the following problem posted below? I just need some simple use case diagrams made for all the systems at play as described, ill do my best to answer any questions you may have, thank you! SYSTEM DETAILS: The warehouse stores items for purchase by customers. To expedite order fulfillment, stock of most items is kept and a minimum reorder is made when stocks are below a set trigger quantity. Items ordered that are not in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT