Question #44630

Let f (x) = ex be defined on [−1, 1]. For each positive integer n ≥ 3, let Pn be the Lagrange interpolation polynomial of f at the n equidis- tant points in [−1,1]. Given a positive error δ, write a function that compute the smallest value of n so that ∥f − Pn∥∞ < δ. For the test case, you can take δ = 10−4.

Expert's answer

Answer on Question #44630 - Math - Other

Let f(x)=exf(x) = e^{x} be defined on [1;1][-1; 1]. For each positive integer n=3n = 3, let PnP_{n} be the Lagrange interpolation polynomial of ff at the nn equidistant points in [1;1][-1; 1]. Given a positive error δ\delta, write a function that computes the smallest value of nn so that fPnL<δ\| f - P_{n} \|_{L^{\infty}} < \delta. For the test case, you can take δ=104\delta = 10^{-4}.

As L(M)=esssupxM\| \cdot \|_{L^{\infty}(M)} = \mathrm{esssup}_{x\in M}|\cdot | and usually during programming we don't consider functions as equivalence classes, we can assume that L(M)=maxxM\| \cdot \|_{L^{\infty}(M)} = \max_{x\in M}|\cdot | Thus, below is written a script which implements required function

Listing 1 (from MatLab): Q44630.m


1 clc
2 clear all
3 %enter error
4 delta=0.0001
5 n=3;
6
7 syms x
8 f=exp(x);
9 err=1;
10 while err>delta
11 X=-1:1/(n-2):1;
12 Y=exp(X);
13
14 %Lagrange
15
16 N=length(X);
17 W=1;
18 for j=1:N
19 W-W*(x-X(j));
20 end;
21 W1=diff(W,x,1);
22 L=0;
23 for i=1:N
24 T=subs(W1,x,X(i));
25 L=L+W.*Y(i)./(T.*(x-X(i)));
26 end;
27 Lnew=simplify(L);
28 Lnew;
29 W=exp(x)-Lnew;
30 W=abs(W);
31 g=matlabFunction(W);
32 m=fminbnd(g,-1,1);
33 err=double(subs(abs(W),x,m))
34
35 n=n+1;
36 end;
37 err
38 n-1


www.AssignmentExpert.com


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS