a matlab question need help!! please!!!!
1 view (last 30 days)
Show older comments
Write a Matlab ’s function newtinterp.m with input arguments (x,y,u), where (xi,yi), i =
1, . . . , n + 1, the interpolation data points and u = [u1, . . . , um] the vector containing the m points on which we want to evaluate the interpolating polynomial. This will compute the coefficients of the interpolating polynomial ai and will return the values zi = pn(ui), i = 1,2,...,m using the previous algorithms.
Finally, consider the function f(x) = sinx, x ∈ [0,2π], and a uniform partition of [0,2π] with 6 points xi, i = 1, . . . , 6. Using your function newtinterp.m compute the interpolating polynomial p5, that interpolates function f at the nodes xi, at 101 equi-distributed points zi ∈ [0,2π]. Verify your results and compare them with those obtained by using the Matlab ’s functions polyfit and polyval.
I have the code like this:
function [p] = newtinterp( x , y , u)
n=length(x)-1;
a=y;
for k=2:n+1
for i=1:k-1
a(k)=(a(k)-a(i))/(x(k)-x(i));
end
end
p=0*u;
for t= 1:length(u)
s=a(end)
for i = n:-1:1
s= a(i)+(u(t)-x(i))*s
end
p(t)=s;
end
and I try to run :
x=linspace(o,2*p,6)
y=sin(x)
newtinterp( x , y , 5)
it does't work.
%
>> newtinterpt(x,y,5)
Undefined function 'newtinterpt' for input arguments of type 'double'. %
Anyone can help me please??
1 Comment
Matt Kindig
on 3 May 2013
You mis-spelled your function in your call. It should be 'newtinterp', not 'newtinterpt'.
Answers (1)
Mar Wan
on 2 May 2021
Find the interpolating polynomial to the function f(x) = e −x cos(νπx) using matlab
for x=-0.67.x=0,x=0.67
and v=67
2 Comments
Steven Lord
on 2 May 2021
This is not related to the original question. Please post it as a new question rather than trying to resurrect an old unrelated question.
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!