[已答复] 保留for循环每次结果

[复制链接]
229 发表于 2014-6-11 20:12:48
A=[0;0.05233333;0.29655555;0.5582222;0.45355555];
P=[0 2;-1 1.5;-1.5 0.5;-0.5 0.5;0 1];
>> for i=2:1:5
b=[1-cos(A(i)) sin(A(i)) -sin(A(i)) 1-cos(A(i)) -(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i))) -(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i))) cos(A(i))*(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i)))+sin(A(i))*(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i))) sin(A(i))* (-(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i))))+cos(A(i))*(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i))) 0.5*(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i)))^2+0.5*(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i)))^2];endfid=fopen('Ldr2.txt','wt');fprintf(fid,'%10.6f*x1*x3+%10.6f*x1*x4+%10.6f*x2*x3+%10.6f*x2*x4+%10.6f*x1+%10.6f*x2+%10.6f*x3+%10.6f*x4+%10.6f;\n',b(1),b(2),b(3),b(4),b(5),b(6),b(7),b(8),b(9));fclose(fid);

希望保留for每次运行的结果  如何更改

5 条回复


转基因奔奔 发表于 2014-6-11 20:29:43
b(i) = 你的等式

229 发表于 2014-6-11 20:36:08

A=[0;0.05233333;0.29655555;0.5582222;0.45355555];
P=[0 2;-1 1.5;-1.5 0.5;-0.5 0.5;0 1];
for i=2:1:5
b(i)=[1-cos(A(i)) sin(A(i)) -sin(A(i)) 1-cos(A(i)) -(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i))) -(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i))) cos(A(i))*(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i)))+sin(A(i))*(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i))) sin(A(i))* (-(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i))))+cos(A(i))*(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i))) 0.5*(P(i,1)-P(1,1)*cos(A(i))+P(1,2)*sin(A(i)))^2+0.5*(P(i,2)-P(1,1)*sin(A(i))-P(1,2)*cos(A(i)))^2];end
fid=fopen('Ldr2.txt','wt');fprintf(fid,'%10.6f*x1*x3+%10.6f*x1*x4+%10.6f*x2*x3+%10.6f*x2*x4+%10.6f*x1+%10.6f*x2+%10.6f*x3+%10.6f*x4+%10.6f;\n',b(1),b(2),b(3),b(4),b(5),b(6),b(7),b(8),b(9));fclose(fid);
type Ldr2.txt

结果是这样

???  In an assignment  A(I) = B, the number of elements in B and
I must be the same.

转基因奔奔 发表于 2014-6-11 20:37:58
b(i) 换成b(i,:)

byf2013 发表于 2014-6-12 11:42:15
把你b(i)后面的那个分号去掉就行了

byf2013 发表于 2014-6-12 11:48:49
而且你这个程序本身就有问题就拿第四行来说cos(A(i)) sin(A(i))这个是什么意思?在matlab中两个变量相乘中间要加*号
您需要登录后才可以回帖 登录 | 注册

本版积分规则

相关帖子
热门教程
站长推荐
快速回复 返回顶部 返回列表