%%Matlab code for Lagrange polynomial
clear all
close all
%All given data point for x and y
xx=[1 2 6];
yy=[0.5403 -0.4161 0.9602];
%answering question b.
%function for which interpolation have to do
f=@(x) cos(x);
%all given x data and y data
x1=0:0.1:8;
y1=f(x1);
%plotting data
hold on
plot(x1,y1,'Linewidth',2)
plot(xx,yy,'r*')
xlabel('x')
ylabel('f(x)')
title('f(x) vs. x plot')
legend('Actual data','Given data point')
%answering question c.
%function for all L(x)
L0=@(x) ((x-2).*(x-6))./5;
L1=@(x) -((x-1).*(x-6))./4;
L2=@(x) ((x-1).*(x-2))./20;
figure(2)
hold on
plot(x1,L0(x1).*f(xx(1)),'Linewidth',2)
plot(x1,L1(x1).*f(xx(2)),'Linewidth',2)
plot(x1,L2(x1).*f(xx(3)),'Linewidth',2)
legend('L0(x)','L1(x)','L2(x)')
xlabel('x')
ylabel('L(x)')
title('L(x) vs. x plot')
%answering question d.
syms x
summ(x)=L0(x)*f(xx(1))+L1(x)*f(xx(2))+L2(x)*f(xx(3));
for i=1:length(x1)
y2(i)=double(summ(x1(i)));
end
%displaying Lagrange function
fprintf('displaying Lagrange function\n')
disp(vpa(summ,2))
figure(3)
hold on
plot(x1,y1,'Linewidth',2)
plot(xx,yy,'r*')
plot(x1,y2,'Linewidth',2)
legend('Actual function','given data point','Lagrange
interpolation')
title('x vs. f(x) plot')
%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%
3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 point...
Consider polynomial interpolation of the function f(x)=1/(1+25x^2) on the interval [-1,1] by (1) an interpolating polynomial determined by m equidistant interpolation points, (2) an interpolating polynomial determined by interpolation at the m zeros of the Chebyshev polynomial T_m(x), and (3) by interpolating by cubic splines instead of by a polynomial. Estimate the approximation error by evaluation max_i |f(z_i)-p(z_i)| for many points z_i on [-1,1]. For instance, you could use 10m points z_i. The cubic spline interpolant can be determined in...
Matlab: please answer all 3 parts and show steps using Matlab inputs ONLY thank you Problem 3. Consider the function f(x) ei cos(2x). (1) Sketch its graph over the interval [0, r] by the following commands: (2) Using h-001 to compute the difference quotient for x = π/6 in [0, π]. The commands are: And the difference quotient is: (3) Using h = 0.01 to approximate the second derivative by computing the difífquo for x = π/6 in [0, π]....
1. Runge's function is written as f(x) = 1 25r2 (a) Develop a plot of this function for the interval from x =-1 to 1 using Matlab (no submission required). Develop the fourth-order Lagrange interpolating polynomial using equispaced function values corresponding to xi =-1,-0.5, 0, 0.5, and 1. (Note that you first need to determine the (a. ) pairs.) Use the polynomial to estimate f(0.9). (b) What is et? (c) Generate a cubic spline using the five data points from...
1. Consider the polynonial Pl (z) of degree 4 interpolating the function f(x) sin(x) on the interval n/4,4 at the equidistant points r--r/4, xi =-r/8, x2 = 0, 3 π/8, and x4 = π/4. Estimate the maximum of the interpolation absolute error for x E [-r/4, π/4 , ie, give an upper bound for this absolute error maxsin(x) P(x) s? Remark: you are not asked to give the interpolation polynomial P(r). 1. Consider the polynonial Pl (z) of degree 4...
please explain and do in matlab Problem 3. Consider the function f(x) e cos(2r). (1) Sketch its graph over the interval [0, m) by the following commands: (2) Using h = 0.01 π/6 in [0, π]. The commands are: to compute the difference quotient for z And the difference quotient is: ( 6 (3) Using h-0.01 to approximate the second derivative by computing the difdifquo for in [0, π). The commands are: And the difdifquo is: Problem 3. Consider the...
Consider the function f(x) 1 25x which is used to test various interpolation methods. For the remainder of this problem consider only the interval [-1, 1] The x-values for the knots (or base-points) of the interpolation algorithm are located at x--1,-0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75 1. (a) Create a "single" figure in Matlab that contains 6 subplots (2x3) and is labelled as figure (777), i.e the figure number is 777. Plot in each subplot the function f(x) using...
Please use Taylor Polynomial series and quadratic formula. 8. (10 points) Consider the equation cos(x)-x = 0. The plot of y-cos(x)-x reve that the equation has a single root lying in the interval [0, 1] (marked with a circle). 0.5 0 0.8 -0.5 0.6 0.4 0.2 Find the best possible approximation for that root. 8. (10 points) Consider the equation cos(x)-x = 0. The plot of y-cos(x)-x reve that the equation has a single root lying in the interval [0,...
4. Consider the periodic function 0, -1<t<- f(t) cos(#(t + 1)), } <t< 0 cos(at), 0<t< 0, }<t<i with f(t) = f(t+2). (a) Determine a general expression for the Fourier series of f. (b) Use MATLAB to plot both f and the sum of the first 5 non-zero terms of the Fourier series for f on the same set of axes for -1<t<3.
Write a MATLAB script to plot the function of f(x) given by: Write a MATLAB script to plot the function of f(x) given by: f(x) = integral x^2 - pi^2/4 x > pi/2 8 * cos x -pi/2 lessthanorequalto x lessthanorequalto pi/2 pi^2/4 - x^2 x < -pi/2
Problem 5. Consider least squares polynomial approximation to f(x) = cos (nx) on x E [-1,1] using the inner product 1. In finding coefficients you will need to compute the integral By symmetry, an 0 for odd n, so we need only consider even n. (a) Make a change of variables and use appropriate identities to transform the integral for a to cos (Bcos 8)cos (ne) de (b) The Bessel function of even order, (x), can be defined by the...