请大神帮我把这段代码改成for循环,是matlab中的m文件,fid=fopen('d:\for_7.wri','r');s=fscanf(fid,'%d',[5,6]);s=s';k(1,:)=[s(1,1),s(1,2),s(1,3),1,0,0,0,0,-s(1,4)*s(1,1),-s(1,4)*s(1,2),-s(1,4)*s(1,3)];k(2,:)=[0,0,0,0,s(1,1),s(1,2),s(1,3)

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 01:31:15

请大神帮我把这段代码改成for循环,是matlab中的m文件,fid=fopen('d:\for_7.wri','r');s=fscanf(fid,'%d',[5,6]);s=s';k(1,:)=[s(1,1),s(1,2),s(1,3),1,0,0,0,0,-s(1,4)*s(1,1),-s(1,4)*s(1,2),-s(1,4)*s(1,3)];k(2,:)=[0,0,0,0,s(1,1),s(1,2),s(1,3)
请大神帮我把这段代码改成for循环,是matlab中的m文件,
fid=fopen('d:\for_7.wri','r');
s=fscanf(fid,'%d',[5,6]);
s=s';
k(1,:)=[s(1,1),s(1,2),s(1,3),1,0,0,0,0,-s(1,4)*s(1,1),-s(1,4)*s(1,2),-s(1,4)*s(1,3)];
k(2,:)=[0,0,0,0,s(1,1),s(1,2),s(1,3),1,-s(1,5)*s(1,1),-s(1,5)*s(1,2),-s(1,5)*s(1,3)];
k(3,:)=[s(2,1),s(2,2),s(2,3),1,0,0,0,0,-s(2,4)*s(2,1),-s(2,4)*s(2,2),-s(2,4)*s(2,3)];
k(4,:)=[0,0,0,0,s(2,1),s(2,2),s(2,3),1,-s(2,5)*s(2,1),-s(2,5)*s(2,2),-s(2,5)*s(2,3)];
k(5,:)=[s(3,1),s(3,2),s(3,3),1,0,0,0,0,-s(3,4)*s(3,1),-s(3,4)*s(3,2),-s(3,4)*s(3,3)];
k(6,:)=[0,0,0,0,s(3,1),s(3,2),s(3,3),1,-s(3,5)*s(3,1),-s(3,5)*s(3,2),-s(3,5)*s(3,3)];
k(7,:)=[s(4,1),s(4,2),s(4,3),1,0,0,0,0,-s(4,4)*s(4,1),-s(4,4)*s(4,2),-s(4,4)*s(4,3)];
k(8,:)=[0,0,0,0,s(4,1),s(4,2),s(4,3),1,-s(4,5)*s(4,1),-s(4,5)*s(4,2),-s(4,5)*s(4,3)];
k(9,:)=[s(5,1),s(5,2),s(5,3),1,0,0,0,0,-s(5,4)*s(5,1),-s(5,4)*s(5,2),-s(5,4)*s(5,3)];
k(10,:)=[0,0,0,0,s(5,1),s(5,2),s(5,3),1,-s(5,5)*s(5,1),-s(5,5)*s(5,2),-s(5,5)*s(5,3)];
k(11,:)=[s(6,1),s(6,2),s(6,3),1,0,0,0,0,-s(6,4)*s(6,1),-s(6,4)*s(6,2),-s(6,4)*s(6,3)];
k(12,:)=[0,0,0,0,s(6,1),s(6,2),s(6,3),1,-s(6,5)*s(6,1),-s(6,5)*s(6,2),-s(6,5)*s(6,3)];
u=[s(1,4),s(1,5),s(2,4),s(2,5),s(3,4),s(3,5),s(4,4),s(4,5),s(5,4),s(5,5),s(6,4),s(6,5)];
u=u';
m=inv((k'*k))*k'*u;

请大神帮我把这段代码改成for循环,是matlab中的m文件,fid=fopen('d:\for_7.wri','r');s=fscanf(fid,'%d',[5,6]);s=s';k(1,:)=[s(1,1),s(1,2),s(1,3),1,0,0,0,0,-s(1,4)*s(1,1),-s(1,4)*s(1,2),-s(1,4)*s(1,3)];k(2,:)=[0,0,0,0,s(1,1),s(1,2),s(1,3)
fid=fopen('d:\for_7.wri','r');
s=fscanf(fid,'%d',[5,6]);
s=s';
k=zeros(12,11);
for i=1:6
k(2*i-1,:)=[s(i,1),s(i,2),s(i,3),1,0,0,0,0,-s(i,4)*s(i,1),-s(i,4)*s(i,2),-s(i,4)*s(i,3)];
k(2*i,:)=[0,0,0,0,s(i,1),s(i,2),s(i,3),1,-s(i,5)*s(i,1),-s(i,5)*s(i,2),-s(i,5)*s(i,3)];
end
u=[s(1,4),s(1,5),s(2,4),s(2,5),s(3,4),s(3,5),s(4,4),s(4,5),s(5,4),s(5,5),s(6,4),s(6,5)];
u=u';
m=inv((k'*k))*k'*u;