I have no clue what i am doing - any and all help would be appreciated - thanks!

Finding an Input Giving a Desired Output
PROBLEM BACKGROUND
In many control problems, the output response of a system to an input is a non-linear function, that function perhaps being non-analytic (for example the output speed of a motor in response to an input voltage may not be easy to express as a mathematical function). One problem that arises is the need to adjust an input (e.g., voltage to a motor) in order to obtain a desired output (e.g., motor speed). A feedback control system can be used, with the output measured and compared with the desired output to determine a change in the input to reduce the error between the actual and desired outputs. In the example of a motor, you could apply some voltage, measure the motor speed, and, if the measured speed is less than the desired speed, increase the voltage). The main question here is by how much should you change the voltage. Feedback control systems make use of the change in the output caused by a change in the input to estimate a next change in the input to create an output closer to the desired output.
Sounds complicated but let’s look at some math, using the motor speed control example. Let the desired motor speed be given by . Unfortunately, we don’t know what voltage V to apply to get this desired speed. Now let’s see if we can develop some algorithm to obtain that speed.
Step 1: First, simply apply some voltage and measure the motor speed, which we find to be . We will assume that the motor speed increases monotonically with voltage. But we don’t know how rapidly. So we apply another voltage in the next step. We will assume, for convenience that the measured motor speed is less that the desired speed, requiring that the voltage be increased.
Step 2: Apply a voltage somewhat larger (but not greatly larger) than (we want to see how the speed changes with small changes in the voltage for reasons that will be more clear later). Again measure the motor speed, which we find to be .
Step 3: The above two measurements provide the change in motor speed resulting from a small change in the voltage. This is essentially the same as obtaining a derivative, as defined by the approximation
.
Step 4: Next, consider the change in voltage that would be required to obtain the desired motor speed. This can not be determined precisely at this time because the relationship S(V) between speed and voltage is non-linear. However, we might use the approximation

which can be solved for the next value giving

I will rewrite the above equation using the terminology “previous value” representing the index n-1, “current value” representing the index n, and “next value” representing the index n+1.
Equation A1
If this equation is used directly, there can be instabilities in which, given a motor speed well below the desired speed, the change in voltage leads to a motor speed well above the desired speed, leading to a new change in voltage and a motor speed again well below the desired speed. For this reason, rather than trying to hit the desired speed in a single step, one “slowly walks toward” the desired speed by using changes in voltage smaller than the above. The FINAL (yes, you can breath a sign of relief) equation for control typically used is therefore,
Equation A2
You need to experiment with an appropriate value of lambda but you may want to try something link . Smaller values will cause the speed to increase more slowly towards the desired value. Larger values may cause instability (speed never converging to desired value).

For the program to be written, we will assume that the function giving the motor speed as a function of voltage is given by

Equation B
PROGRAMMING PROBLEM
The programming problem involves writing a program to implement equation A above in order to proceed through a sequence of voltage steps to give a desired motor speed (select the desired speed to be in the range between 1.5 and 8.5). Given the previous and current values of the voltage, equation A gives the next value of voltage. Equation B is used to calculate the motor speed for each value of voltage. The program will be in the form of a repeating loop which continues to adjust the voltage until the desired speed is achieved (to some specified accuracy). As an example of a specified accuracy, you will exit the loop when the measured speed differs from the desired speed by some small percentage. This can be stated mathematically as
Equation C
I will provide an outline of a possible program. You can make adjustments as appropriate. I have not provided the entire program details, just an outline. To implement the loop that increments (or decrements) the voltage until the desired speed is obtain, I have used a “do-while” loop. Other types of loops are also fine.

#include <...> // as needed
using namespace std;
int main()
{
float declare date types as needed;
char done(‘n’); // this is used to terminate loop.
char dummy; // See whether you understand why I use this below.
cout << “Enter desired motor speed between 1.5 and 8.5 “;
cin >> variable you are using for the desired value;
cout << endl << “Enter accuracy of motor speed desired (in %);
cin >> variable you use for “Accuracy” in equation C;
cout << endl << “Enter starting value for voltage “”
cin >> variable you are using for “previous” voltage;
cout << endl << “Enter value of voltage increment for start;
Previous speed = Use equation B with previous voltage;
current voltage = previous voltage + starting voltage increment;
Current speed = Use equation B with current voltage;
/* The above instructions set up the previous and current
values of voltage and speed that will be used in the loop
to calculate the next voltage and speed.

The next instruction gives heading for data printed
*/

do
{
Using equation A1 and A2, calculate the “next” voltage;
Using equation B and “next” voltage, calculate the “next” speed

cout << endl << value of “next voltage” << value of “next speed”
<< value of “desired speed;
cin >> dummy;
/* The “cout” instruction above prints out the values so that you
can see how your program is working towards obtaining the
correct speed by adjusting voltages. The “cin” instruction
causes the program to stop (so you can look at the values) until
you enter anything (including a carriage return).

The next four instructions do the following:
1. Set the “previous” values for the next pass through the
loop equal to the “current” values.
2. Set the “current” values for the next pass through the
loop equal to the “next” values calculated during this
pass through the loop. Make sure you understand why this
is done.
*/
Set “previous voltage” equal to “current voltage”;
Set “previous speed” equal to “current speed”;
Set “current voltage” equal to “next voltage”;
Set “current speed” equal to “next speed”;

Calculate the error in the speed and determine whether the
desired speed has been found, to within specified accuracy.
If desired speed has been found, set variable “done” equal to
the character ‘y’, i.e. done = ‘y’.

} while(done != ‘y’);
cout << endl << “Congrats. “;
return 0;
}

.

Step 4: Next, consider the change in voltage that would be required to obtain the desired motor speed. This can not be determined precisely at this time because the relationship S(V) between speed and voltage is non-linear. However, we might use the approximation

which can be solved for the next value giving

I will rewrite the above equation using the terminology “previous value” representing the index n-1, “current value” representing the index n, and “next value” representing the index n+1.
Equation A1
If this equation is used directly, there can be instabilities in which, given a motor speed well below the desired speed, the change in voltage leads to a motor speed well above the desired speed, leading to a new change in voltage and a motor speed again well below the desired speed. For this reason, rather than trying to hit the desired speed in a single step, one “slowly walks toward” the desired speed by using changes in voltage smaller than the above. The FINAL (yes, you can breath a sign of relief) equation for control typically used is therefore,
Equation A2
You need to experiment with an appropriate value of lambda but you may want to try something link . Smaller values will cause the speed to increase more slowly towards the desired value. Larger values may cause instability (speed never converging to desired value).

For the program to be written, we will assume that the function giving the motor speed as a function of voltage is given by

Equation B
PROGRAMMING PROBLEM
The programming problem involves writing a program to implement equation A above in order to proceed through a sequence of voltage steps to give a desired motor speed (select the desired speed to be in the range between 1.5 and 8.5). Given the previous and current values of the voltage, equation A gives the next value of voltage. Equation B is used to calculate the motor speed for each value of voltage. The program will be in the form of a repeating loop which continues to adjust the voltage until the desired speed is achieved (to some specified accuracy). As an example of a specified accuracy, you will exit the loop when the measured speed differs from the desired speed by some small percentage. This can be stated mathematically as
Equation C
I will provide an outline of a possible program. You can make adjustments as appropriate. I have not provided the entire program details, just an outline. To implement the loop that increments (or decrements) the voltage until the desired speed is obtain, I have used a “do-while” loop. Other types of loops are also fine.

#include <...> // as needed
using namespace std;
int main()
{
float declare date types as needed;
char done(‘n’); // this is used to terminate loop.
char dummy; // See whether you understand why I use this below.
cout << “Enter desired motor speed between 1.5 and 8.5 “;
cin >> variable you are using for the desired value;
cout << endl << “Enter accuracy of motor speed desired (in %);
cin >> variable you use for “Accuracy” in equation C;
cout << endl << “Enter starting value for voltage “”
cin >> variable you are using for “previous” voltage;
cout << endl << “Enter value of voltage increment for start;
Previous speed = Use equation B with previous voltage;
current voltage = previous voltage + starting voltage increment;
Current speed = Use equation B with current voltage;
/* The above instructions set up the previous and current
values of voltage and speed that will be used in the loop
to calculate the next voltage and speed.

The next instruction gives heading for data printed
*/

do
{
Using equation A1 and A2, calculate the “next” voltage;
Using equation B and “next” voltage, calculate the “next” speed

cout << endl << value of “next voltage” << value of “next speed”
<< value of “desired speed;
cin >> dummy;
/* The “cout” instruction above prints out the values so that you
can see how your program is working towards obtaining the
correct speed by adjusting voltages. The “cin” instruction
causes the program to stop (so you can look at the values) until
you enter anything (including a carriage return).

The next four instructions do the following:
1. Set the “previous” values for the next pass through the
loop equal to the “current” values.
2. Set the “current” values for the next pass through the
loop equal to the “next” values calculated during this
pass through the loop. Make sure you understand why this
is done.
*/
Set “previous voltage” equal to “current voltage”;
Set “previous speed” equal to “current speed”;
Set “current voltage” equal to “next voltage”;
Set “current speed” equal to “next speed”;

Calculate the error in the speed and determine whether the
desired speed has been found, to within specified accuracy.
If desired speed has been found, set variable “done” equal to
the character ‘y’, i.e. done = ‘y’.

} while(done != ‘y’);
cout << endl << “Congrats. “;
return 0;
}

#include <...> // as needed

using namespace std;
int main()
{
float declare date types as needed;
char done(‘n’); // this is used to terminate loop.
char dummy; // See whether you understand why I use this below.
cout << “Enter desired motor speed between 1.5 and 8.5 “;
cin >> variable you are using for the desired value;
cout << endl << “Enter accuracy of motor speed desired (in %);
cin >> variable you use for “Accuracy” in equation C;
cout << endl << “Enter starting value for voltage “”
cin >> variable you are using for “previous” voltage;
cout << endl << “Enter value of voltage increment for start;
Previous speed = Use equation B with previous voltage;
current voltage = previous voltage + starting voltage increment;
Current speed = Use equation B with current voltage;
/* The above instructions set up the previous and current
values of voltage and speed that will be used in the loop
to calculate the next voltage and speed.

The next instruction gives heading for data printed
*/

do
{
Using equation A1 and A2, calculate the “next” voltage;
Using equation B and “next” voltage, calculate the “next” speed

cout << endl << value of “next voltage” << value of “next speed”
<< value of “desired speed;
cin >> dummy;
/* The “cout” instruction above prints out the values so that you
can see how your program is working towards obtaining the
correct speed by adjusting voltages. The “cin” instruction
causes the program to stop (so you can look at the values) until
you enter anything (including a carriage return).

The next four instructions do the following:
1. Set the “previous” values for the next pass through the
loop equal to the “current” values.
2. Set the “current” values for the next pass through the
loop equal to the “next” values calculated during this
pass through the loop. Make sure you understand why this
is done.
*/
Set “previous voltage” equal to “current voltage”;
Set “previous speed” equal to “current speed”;
Set “current voltage” equal to “next voltage”;
Set “current speed” equal to “next speed”;

Calculate the error in the speed and determine whether the
desired speed has been found, to within specified accuracy.
If desired speed has been found, set variable “done” equal to
the character ‘y’, i.e. done = ‘y’.

} while(done != ‘y’);
cout << endl << “Congrats. “;
return 0;
}

It seems like you are looking for help in writing a program to control the speed of a motor. Based on the information you provided, here is an outline of a possible program to achieve this:

```cpp
#include <...> // include necessary libraries

using namespace std;

int main() {
// declare necessary variables
float desiredSpeed;
float accuracy;
float previousVoltage;
float currentVoltage;
float currentSpeed;
char done = 'n';
char dummy;

// get user input for desired speed and accuracy
cout << "Enter desired motor speed between 1.5 and 8.5: ";
cin >> desiredSpeed;
cout << endl << "Enter accuracy of motor speed desired (in %): ";
cin >> accuracy;
cout << endl << "Enter starting value for voltage: ";
cin >> previousVoltage;
cout << endl << "Enter value of voltage increment for start: ";
cin >> currentVoltage;

// calculate previous and current speeds based on voltage
float previousSpeed = calculateSpeed(previousVoltage);
currentSpeed = calculateSpeed(currentVoltage);

// print header for data
cout << "Next Voltage\tNext Speed\tDesired Speed" << endl;

// start loop to adjust voltage until desired speed is achieved
do {
// calculate next voltage and next speed using equation A1 and A2
float nextVoltage = calculateNextVoltage(previousVoltage, currentVoltage, previousSpeed, currentSpeed);
float nextSpeed = calculateSpeed(nextVoltage);

// print values of next voltage, next speed, and desired speed
cout << nextVoltage << "\t" << nextSpeed << "\t" << desiredSpeed << endl;

cin >> dummy; // pause program until user enters anything

// update previous and current values for next iteration
previousVoltage = currentVoltage;
previousSpeed = currentSpeed;
currentVoltage = nextVoltage;
currentSpeed = nextSpeed;

// check if desired speed has been reached within specified accuracy
if (abs(currentSpeed - desiredSpeed) <= accuracy/100 * desiredSpeed) {
done = 'y';
}

} while(done != 'y');

cout << "Congrats." << endl;
return 0;
}

```

Please note that this is just an outline and you will need to fill in the missing parts. You will also need to define functions `calculateSpeed` and `calculateNextVoltage` based on the equations provided in your problem statement. Make sure to include any necessary libraries and adjust the code according to your specific requirements.