matlab 不能运行 Function definitions are not permitted at the prompt or in scriptsfunction y=ex32n=21;x=linspace(-5,5,n)';h=(5-(-5))/(n-1);y=1./(1+x.^2);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));endy=y(1,:);pz=[];v=linspace

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 03:33:11
matlab不能运行Functiondefinitionsarenotpermittedatthepromptorinscriptsfunctiony=ex32n=21;x=linspace(-5,5

matlab 不能运行 Function definitions are not permitted at the prompt or in scriptsfunction y=ex32n=21;x=linspace(-5,5,n)';h=(5-(-5))/(n-1);y=1./(1+x.^2);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));endy=y(1,:);pz=[];v=linspace
matlab 不能运行 Function definitions are not permitted at the prompt or in scripts
function y=ex32
n=21;
x=linspace(-5,5,n)';
h=(5-(-5))/(n-1);
y=1./(1+x.^2);
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
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--';

matlab 不能运行 Function definitions are not permitted at the prompt or in scriptsfunction y=ex32n=21;x=linspace(-5,5,n)';h=(5-(-5))/(n-1);y=1./(1+x.^2);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));endy=y(1,:);pz=[];v=linspace
for j=2;n,中间应该是:号
plot(v,pz,'r+-',v,1./(1+v.^2),'g--'; 最后少了个括号
文件应保存在ex32.m里
修改后如下,测试可以运行
function y=ex32
n=21;
x=linspace(-5,5,n)';
h=(5-(-5))/(n-1);
y=1./(1+x.^2);
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
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--');