matlab作图:找出函数f(x)=1/(x^2+1)的20阶插值多项式p(x),做出f(x)和p(x)的图形,发生错误,代码如下function y = ex217n = 21;x = linspace(-5,5,n)’;h = (5-(-5))/(n-1);y = 1./(1+x.^2);% form the differences tablefor j = 2:n,y(1:n
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 04:42:51
matlab作图:找出函数f(x)=1/(x^2+1)的20阶插值多项式p(x),做出f(x)和p(x)的图形,发生错误,代码如下function y = ex217n = 21;x = linspace(-5,5,n)’;h = (5-(-5))/(n-1);y = 1./(1+x.^2);% form the differences tablefor j = 2:n,y(1:n
matlab作图:找出函数f(x)=1/(x^2+1)的20阶插值多项式p(x),做出f(x)和p(x)的图形,发生错误,
代码如下
function y = ex217
n = 21;
x = linspace(-5,5,n)’;
h = (5-(-5))/(n-1);
y = 1./(1+x.^2);
% form the differences table
for j = 2:n,
y(1:n+1-j,j) = diff(y(1:n+2-j,j-1))./(x(j:n)-x(1:n+1-j));
end
% newton coeff(以上为ex217.m里的内容)
y = y(1,:);
pz = [ ];
v = linspace(-5,5,80);
for t = v,
z = y(n);
for j = n-1:-1:1,
z = z * ( t - x(j) ) + y(j);
end
pz = [pz z];
end
plot(v,pz,’r+-’,v,1./(1+v.^2),’g--’)
运行后提示?Undefined function or variable "y".
matlab作图:找出函数f(x)=1/(x^2+1)的20阶插值多项式p(x),做出f(x)和p(x)的图形,发生错误,代码如下function y = ex217n = 21;x = linspace(-5,5,n)’;h = (5-(-5))/(n-1);y = 1./(1+x.^2);% form the differences tablefor j = 2:n,y(1:n
n = 21;%%%function y=ex217去掉,运行即可
x = linspace(-5,5,n)';转置符号,英文输入
h = (5-(-5))/(n-1);
y = 1./(1+x.^2);
% form the differences table
for j = 2:n,
y(1:n+1-j,j) = diff(y(1:n+2-j,j-1))./(x(j:n)-x(1:n+1-j));
end
% newton coeff(以上为ex217.m里的内容)
y = y(1,:);
pz = [ ];
v = linspace(-5,5,80);
for t = v,
z = y(n);
for j = n-1:-1:1,
z = z * ( t - x(j) ) + y(j);
end
pz = [pz z];
end
plot(v,pz,’r+-‘,v,1./(1+v.^2),‘g--’)%%引号英文输入