hey!! i am stuck here. i am new. help please.

my task is to do this:
i have wrote the codde as:
clc
clear all
xdata=linspace(-1,1,9);
ydata=1./(1+14*xdata.^2);
x=linspace(-1,1,1000);
y=lagrangeInterp(xdata,ydata,x);
plot(x,y,'b',xdata,ydata,'*r');
function [yhat]=lagrangeInterp(x,y,interpx)
X=x;
f=y;
x=interpx;
l=0;
for i=1:length(X)
li=1;
for j=1:length(X)
if i~=j
li=(li).*((x-X(j))/(X(i)-X(j)));
end
end
l=(l)+((li)*f(i));
end
yhat=l;
end
Can you tell me what will happen if we use nodes that are not equispaced in x. Instead,
use the Chebyshev nodes {xk}given by
xk = -cos(pi * k/n); k = 0, 1, ..... ,n

 Accepted Answer

Andy
Andy on 22 Oct 2020
You do not say why this is wrong, the code runs. Is there an issue with the number of nodes and the linspace. The question says use n=9 (i.e. 10 nodes) but using xdata=linspace(-1,1,9); only generates 9 nodes. If you change to
xdata=linspace(-1,1,10);
This gives 10 nodes and perhaps the answer you are looking for.

5 Comments

i get it. but i want to find the plots mentioned in part (ii) named as plots of "interpolant vs x" ,original function vs x, and the set. i am unable to get answers for that.
This adds some data for the original function and adds it to the plot. Just insert/replace into your code.
xdata1=linspace(-1,1,200);
ydata1=1./(1+14*xdata1.^2);
plot(x,y,'b',xdata1,ydata1,'g',xdata,ydata,'*r');
got it!!
can you tell me what will happen if we use nodes that are not equispaced in x. Instead,
use the Chebyshev nodes {xk}given by
xk = -cos(pi * k/n); k = 0, 1, ..... ,n
Sorry, I can't help with that, I'm not familiar with use of the interpolation functions.
Can you tag someone who can?/

Sign in to comment.

More Answers (0)

Categories

Asked:

on 22 Oct 2020

Edited:

on 22 Oct 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!