title: how to make a formula to find the value of D from values in another formula
body: <p>In my Pulse Wave generator, I need to find the value of cyclePoint (c) from cycleFrequency (f), cycleRange (r), minDutyCycle (m) and dutyCycle d.</p>
  
  <p>Here is a formula that I made that finds the value of dutyCycle (d) from the other value
  D = ((c/(f/2))r)+m
  <a href="https://i.stack.imgur.com/zKEm2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zKEm2.png" alt="Formula to find duty cycle"></a></p>
  
  <p>I'm not the best at algebra so I probably used the brackets wrong.</p>
  
  <p>Here is my code</p>
  
  <pre><code>public class PulseGenerator extends SquareGenerator {
  
      // constants
      public static final double DEF_MIN_DUTY_CYCLE = 0.05;
      public static final double DEF_MAX_DUTY_CYCLE = 0.95;
      public static final double DEF_CYCLE_FREQ = 2;
      public static final double DEF_HOLD_CYCLE = 0;
  
      // instance variables
      double minDutyCycle;
      double maxDutyCycle;
      double cycleFreq;
      double holdCycle;
      double dutyCycleRange;
      boolean setDirection;
  
      // constructor
      public PulseGenerator(double amplitude, double frequency, int bitRate,
              double duration, double dutyCycle, double minDutyCycle,
              double maxDutyCycle, double cycleFreq, double holdCycle) {
          super(amplitude, frequency, bitRate, duration, dutyCycle);
          // sample data
          squareSample = new int[sampleLength];
          calculateAmpLimit();
          this.dutyCycle = dutyCycle;
          waveLength = sampleRate / this.frequency;
          this.minDutyCycle = minDutyCycle;
          this.maxDutyCycle = maxDutyCycle;
          this.cycleFreq = cycleFreq * sampleRate;
          this.holdCycle = holdCycle * sampleRate;
          dutyCycleRange = this.maxDutyCycle - this.minDutyCycle;
          setDirection = false;
      }
  
      // one arg cunstructor
      public PulseGenerator(double frequency) {
          this(AMPLITUDE, frequency, BIT_RATE, DURATION, DEF_DUTY_CYCLE,
                  DEF_MIN_DUTY_CYCLE, DEF_MAX_DUTY_CYCLE, DEF_CYCLE_FREQ,
                  DEF_HOLD_CYCLE);
      }
  
      // no args constructor
      public PulseGenerator() {
          this(AMPLITUDE, FREQUENCY, BIT_RATE, DURATION, DEF_DUTY_CYCLE,
                  DEF_MIN_DUTY_CYCLE, DEF_MAX_DUTY_CYCLE, DEF_CYCLE_FREQ,
                  DEF_HOLD_CYCLE);
      }
  
      // generate waveform method
      @Override
      public int[] generateWaveForm() {
  
          // define the decimal j
          double j = 1;
  
          // define cycle point
          // here is where I need to find the value of cycle point
          int cyclePoint = (int)((dutyCycle * (cycleFreq / 2) - minDutyCycle) / dutyCycleRange);
  
          System.out.println("Cycle point: " + cyclePoint);
  
          // generate the actual waveform
          for (int i = 0; i &lt; sampleLength; i++, j++) {
  
              double waveCycleRatio = waveLength * dutyCycle;
  
              // same as square
              // draws the wave
              if (j - waveCycleRatio &lt; 0.0) {
                  finePoint = 1.0;
              } else if (j - waveCycleRatio &gt;= 0.0 
                      &amp;&amp; j - waveCycleRatio &lt; 1) {
                  finePoint = 0 - (j - waveCycleRatio - 0.5) * 2;
              } else if (j - waveLength &lt; 0.0) {
                  finePoint = -1.0;
              } else if (j - waveLength &gt;= 0.0) {
                  finePoint = (j - waveLength - 0.5) * 2;
              }
  
              // checks if j is equal to wavelength
              if (j == waveLength) {
                  j = 1;
              } else if (j - waveLength &gt; 0.0 &amp;&amp; j - waveLength &lt; 1.0) {
                  j = (j - waveLength);
              }
              point = (int)(finePoint * ampLimit);
              squareSample[i] = point;
  
              if (holdCycle &gt; 0) {
                  holdCycle--;
              } else {
                  // implementation of formula to find duty cycle
                  dutyCycle = (cyclePoint / (cycleFreq / 2) * dutyCycleRange)
                          + minDutyCycle;
                  if (cyclePoint &lt; cycleFreq / 2 &amp;&amp; !setDirection) {
                      cyclePoint++;
                  } else if (cyclePoint &gt;= cycleFreq / 2 &amp;&amp; !setDirection) {
                      cyclePoint--;
                      setDirection = true;
                  } else if (cyclePoint &gt; 0 &amp;&amp; setDirection) {
                      cyclePoint--;
                  } else if (cyclePoint &lt;= 0 &amp;&amp; setDirection) {
                      cyclePoint++;
                      setDirection = false;
                  }
              }
          }
  
          // return the sample data
          return squareSample;
      }
  
  }
  </code></pre>