Matlab 编程求助
程序如下:functiony=K(k)%programtocomputethecompleteelipticintegralsK(k)%Usingthearith-geo...
程序如下:
function y=K(k)
%program to compute the complete eliptic integrals K(k)
%Using the arith-geom mean method
[m n]= size(k);
if m+ n= =2
K=[k k];
end
if m= =1
k= k';
end
a(:, 1)=ones(k);
b(:, 1)=sqrt(ones(k)-k.*k);
c(:, 1)=k;
i=1;
while max(c(: ,1))>eps
a(:, i+ 1)=.5*(a(a:,i)+b(:,i));
b(:, i+ 1)=sqrt(a(:,i).*b(:,i));
c(:, i+ 1)=.5*(a(:,i)-b(:,i));
i=i+1
end
t=pi*ones(k)./(2*a(:,i));
if m+n= =2
y=t(1,:);
elseif m= =1
y= t';
else
y= t;
end
运行debug后提示
??? Error: File: F:\matlab7\work\K.m Line: 5 Column: 8
The expression to the left of the equals sign is not a valid target for an assignment.
经过修改后 问题为 ??? Error: File: F:\matlab7\work\K.m Line: 16 Column: 23
Incomplete or misformed expression or statement. 展开
function y=K(k)
%program to compute the complete eliptic integrals K(k)
%Using the arith-geom mean method
[m n]= size(k);
if m+ n= =2
K=[k k];
end
if m= =1
k= k';
end
a(:, 1)=ones(k);
b(:, 1)=sqrt(ones(k)-k.*k);
c(:, 1)=k;
i=1;
while max(c(: ,1))>eps
a(:, i+ 1)=.5*(a(a:,i)+b(:,i));
b(:, i+ 1)=sqrt(a(:,i).*b(:,i));
c(:, i+ 1)=.5*(a(:,i)-b(:,i));
i=i+1
end
t=pi*ones(k)./(2*a(:,i));
if m+n= =2
y=t(1,:);
elseif m= =1
y= t';
else
y= t;
end
运行debug后提示
??? Error: File: F:\matlab7\work\K.m Line: 5 Column: 8
The expression to the left of the equals sign is not a valid target for an assignment.
经过修改后 问题为 ??? Error: File: F:\matlab7\work\K.m Line: 16 Column: 23
Incomplete or misformed expression or statement. 展开
1个回答
展开全部
代码巨多问题
部分问题见注释
function y=K(k)
%program to compute the complete eliptic integrals K(k)
%Using the arith-geom mean method
[m n]= size(k); % mm之间必须有,
if m+ n= =2 % 两=之间有空格
K=[k k];
end
if m= =1 % 不解释
k= k';
end
a(:, 1)=ones(k);
b(:, 1)=sqrt(ones(k)-k.*k);
c(:, 1)=k;
i=1;
while max(c(: ,1))>eps
a(:, i+ 1)=.5*(a(a:,i)+b(:,i)); %a(a:,i)这个a是什么意思
b(:, i+ 1)=sqrt(a(:,i).*b(:,i));
c(:, i+ 1)=.5*(a(:,i)-b(:,i));
i=i+1
end
t=pi*ones(k)./(2*a(:,i));
if m+n= =2
y=t(1,:);
elseif m= =1
y= t';
else
y= t;
end
部分问题见注释
function y=K(k)
%program to compute the complete eliptic integrals K(k)
%Using the arith-geom mean method
[m n]= size(k); % mm之间必须有,
if m+ n= =2 % 两=之间有空格
K=[k k];
end
if m= =1 % 不解释
k= k';
end
a(:, 1)=ones(k);
b(:, 1)=sqrt(ones(k)-k.*k);
c(:, 1)=k;
i=1;
while max(c(: ,1))>eps
a(:, i+ 1)=.5*(a(a:,i)+b(:,i)); %a(a:,i)这个a是什么意思
b(:, i+ 1)=sqrt(a(:,i).*b(:,i));
c(:, i+ 1)=.5*(a(:,i)-b(:,i));
i=i+1
end
t=pi*ones(k)./(2*a(:,i));
if m+n= =2
y=t(1,:);
elseif m= =1
y= t';
else
y= t;
end
更多追问追答
追问
我就是去掉那个a 还是会提示同样的错误出来 到底是怎么回事呢
追答
调试通过版
function y=K(k)
[m n]= size(k);
if m+ n==2
K=[k k];
end
if m==1
k= k';
end
a(:, 1)=ones(k);
b(:, 1)=sqrt(ones(k)-k.*k);
c(:, 1)=k;
i=1;
while max(c(: ,1))>eps
a(:, i+ 1)=.5*(a(:,i)+b(:,i));
b(:, i+ 1)=sqrt(a(:,i).*b(:,i));
c(:, i+ 1)=.5*(a(:,i)-b(:,i));
i=i+1
end
t=pi*ones(k)./(2*a(:,i));
if m+n==2
y=t(1,:);
elseif m==1
y= t';
else
y= t;
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询