谢谢楼上两位的解答!那个问题我已经解决了,不是你们说的那样,错误的原因在于变量不能定义成数值型,因为它是符号型的,最主要的错误是没有生成一个列,我生成一个列之后再把里面的元素改为f(i)就行了。后来我又解决的很多错误,不过现在有个很无语的错误,就是END也会报错??!!!
function [p1,S1]= savepeople(r,e)
X=[xlsread('C:\Users\hp\Desktop\original data.xlsx','sheet1','a1:a33')]';
Y=[xlsread('C:\Users\hp\Desktop\original data.xlsx','sheet1','a1:a33')]';
R=zeros(3,3);
A=zeros(3,3);
A0=zeros(3,1);
R0=zeros(3,1);
I=eye(3,3);
syms i a b c a0 b0 c0 u;
A=sym('A',[3 3]);
A0=sym('A0',[3 1]);
R0=sym('R0',[3 1]);
R=sym('R',[3 3]);
YA=sym('YA',[33 1]);
YF=sym('YF',[33 1]);
YS=sym('YS',[33 1]);
WS=sym('WS',[33 1]);
for i=1:1:33
YA(i,1)=a+b*exp(c*X(i));
YF(i,1)=sqrt((Y(i)-YA(i,1))^2);
YS(i,1)=(Y(i)-YA(i,1))^2;
end
S=0;
for i=1:1:33
S=YS(i,1)+S;
end
u=0;
a0=55.16;
b0=-54.04;
c0=0.01378;
p=[a b c];
p0=[a0 b0 c0];
dp=[0 0 0];
p1=p0+dp;
S1=subs(S,'a',p1(1));
S1=subs(S1,'b',p1(2));
S1=subs(S1,'c',p1(3));
S0=0;
while u<1.1 && S1>r && S1-S0>e
while S1>S0;
u=u+0.1;
for m=1:1:3
for n=1:1:3
w1(i)=diff(YF(i,1),p(m),1);
w2(i)=diff(YF(i,1),p(n),1);
w(i)=diff(YF(i,1),p(m),1)*diff(YF(i,1),p(n),1);
ws=0;
for i=1:1:33
ws=w(i)+ws;
end
A(m,n)=ws;
end
ws1=0;
for i=1:1:33
ws1=w1(i)+ws1;
end
A0(m,1)=-ws1*YF(i,1);
end
for m=1:1:3
for n=1:1:3
R(m,n)=A(m,n)/sqrt(A(m,m)*A(n,n));
end
R0(m,1)=A0(m,1)/sqrt(A(m,m));
end
dp1=(R+u*I)\R0;
for t=1:1:3
dp1=sym('dp1',[3 1]);
dp1(t,1)=dp1(t,1)/sqrt(A(t,t));
end
p0=p1;
p1=p1+[dp1]';
S=subs(S,a,p1(1));
S=subs(S,b,p1(2));
S=subs(S,c,p1(3));
S0=subs(S,a,p0(1));
S0=subs(S,b,p0(2));
S0=subs(S,c,p0(3));
end
end
end
??? Error using ==> sym.sym>notimplemented at 2621
Function 'gt' is not implemented for MuPAD symbolic objects.
Error in ==> sym.sym>sym.gt at 801
notimplemented('gt');
Error in ==> savepeople at 90
end
这是倒数第三个END