Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

octave - Why my loop print every results even though im not using printf

Why my loop print every results even though im not using printf. this is my coding. the result is print as matrix for every loop that been executed

r1=0.963;
r2=0.764;
r3=0.528;
r4=1.815;
r5=0.778;
phi1=0*(pi/180);
phi2l=0*(pi/180);
phi2u=90*(pi/180);
phi2ro=90*(pi/180);
printf("    phi-1     phi-2     phi-3     x-p     y-p
");
printf("--------------------------------------------------
");
do
  phi2r=((phi2l+phi2u)/2); #CALCULATE PHI2R
  fphi2l=((r1*cos(phi1)+r2*cos(phi2l)-r4)^2+(r1*sin(phi1)+r2*sin(phi2l))^2-(r3^2)); #EXECUTE FUNCTION USING PHI2L
  fphi2r=((r1*cos(phi1)+r2*cos(phi2r)-r4)^2+(r1*sin(phi1)+r2*sin(phi2r))^2-(r3^2)); #EXECUTE FUNCTION USING PHI2R
  check=fphi2l*fphi2r; #CALCULATE VALUE FOR CONDITION
  if(check<0)
  {
    phi2u=phi2r;
  }
  endif
  if(check>0)
  {
    phi2l=phi2r;
  }
  endif
  error=abs(phi2r-phi2ro)/phi2r; #CALCULATE ERROR
  phi2ro=phi2r;
until(error<10^-8)
phi2=phi2r;
phi3=asin((r1*sin(phi1)+r2*sin(phi2))/r3);
phi3c=acos((r1*cos(phi1)+r2*cos(phi2)-r4)/r3);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have a syntax "error" in your if blocks. In octave you don't need to enclose the if "block" in braces. What you're written effectively wraps that assignment inside a 'cell'. And because the 'cell' statement isn't terminated by a semicolon (note that the semicolon is inside the cell!), the resulting cell gets printed on the terminal.

You can just do this instead:

if check > 0
  phi2l = phi2r;
endif

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...