matlab计算一个函数在多个点的值程序结果为什么是这样?自变量和变量都是数组 10
程序fori=1:11x(i)=cos((23-2*i)*pi/22);y(i)=1/(1+x(i).^2);fprintf('y(%f)=%f\n',x,y);end结...
程序
for i=1:11
x(i)=cos((23-2*i)*pi/22);
y(i)=1/(1+x(i).^2);
fprintf('y(%f)=%f\n',x,y);
end
结果为什么不是11个点的值,而是下面的计算结果,至少有30个值。
y(-0.989821)=0.505115
y(-0.989821)=-0.909632
y(0.505115)=0.547216
y(-0.989821)=-0.909632
y(-0.755750)=0.505115
y(0.547216)=0.636473
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(0.505115)=0.547216
y(0.636473)=0.773819
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.505115
y(0.547216)=0.636473
y(0.773819)=0.926464
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.000000
y(0.505115)=0.547216
y(0.636473)=0.773819
y(0.926464)=1.000000
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.000000
y(0.281733)=0.505115
y(0.547216)=0.636473
y(0.773819)=0.926464
y(1.000000)=0.926464
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.000000
y(0.281733)=0.540641
y(0.505115)=0.547216
y(0.636473)=0.773819
y(0.926464)=1.000000 展开
for i=1:11
x(i)=cos((23-2*i)*pi/22);
y(i)=1/(1+x(i).^2);
fprintf('y(%f)=%f\n',x,y);
end
结果为什么不是11个点的值,而是下面的计算结果,至少有30个值。
y(-0.989821)=0.505115
y(-0.989821)=-0.909632
y(0.505115)=0.547216
y(-0.989821)=-0.909632
y(-0.755750)=0.505115
y(0.547216)=0.636473
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(0.505115)=0.547216
y(0.636473)=0.773819
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.505115
y(0.547216)=0.636473
y(0.773819)=0.926464
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.000000
y(0.505115)=0.547216
y(0.636473)=0.773819
y(0.926464)=1.000000
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.000000
y(0.281733)=0.505115
y(0.547216)=0.636473
y(0.773819)=0.926464
y(1.000000)=0.926464
y(-0.989821)=-0.909632
y(-0.755750)=-0.540641
y(-0.281733)=0.000000
y(0.281733)=0.540641
y(0.505115)=0.547216
y(0.636473)=0.773819
y(0.926464)=1.000000 展开
2个回答
展开全部
看不懂你问的啥意思。如果你的意思是要求你编的函数输入变量只取整数的话在程序开头加:
if
rem(input,1)~=0
error('输入错误');
end
if
rem(input,1)~=0
error('输入错误');
end
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询