a matlab question need help!! please!!!!
이전 댓글 표시
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
Matt Kindig
2013년 5월 3일
You mis-spelled your function in your call. It should be 'newtinterp', not 'newtinterpt'.
답변 (1개)
Mar Wan
2021년 5월 2일
0 개 추천
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
Mar Wan
2021년 5월 2일
could you plz answer this?
Steven Lord
2021년 5월 2일
This is not related to the original question. Please post it as a new question rather than trying to resurrect an old unrelated question.
카테고리
도움말 센터 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!