0
$\begingroup$

I need to write a for loop that tests multiple values in a function until the output is a multiple of 180.

i.e. it starts the number i'm testing at zero, checks if the result is a multiple of 180 or very close to one, and if it isn't, it increases the number i'm testing by some small increment and tests again, printing out the final number that produces a multiple of 180.

Is there a function for this in octave? Some acceptable outputs would be 359.9, 179.9 or 541. I have thought about using the remainder function but that just divides the two numbers.

$\endgroup$

1 Answer 1

3
$\begingroup$

modulo operation is the cleanest, you could then compare the output of the modulo operator to see if it's less than your threshold for "very close"

$\endgroup$
1
  • $\begingroup$ One could also do something like checking $abs(sin(x*\pi/180)) < \epsilon$. $\endgroup$ Feb 18, 2023 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.