C++ Project #3 Need Help With Formula

Posts 16–18 of 18 · Page 2 of 2
Tell you're professor he's a fucking idiot. Optimizing your code to make it run more efficiently and succinctly is of paramount importance to programming. What a twat. Looks like you're going to have to go with Wes's original idea:

start the "depth" value at 0.00f.
start a loop up to either |width/2| or |length/2| (whichever is smaller), incrementing by 0.01f each iteration (or however many decimal places you need to be accurate to)
compare the volume at this value of "depth" to the previously acquired volume.
If the volume at this "depth" is smaller than the previous volume, exit the loop and subtract 0.01f from the current "depth" value (so you're effectively backtracking to the maximised volume depth)
return depth.
????
profit.

Pseudocode:
Code:
declare depth and volumevariable;
declare upperboundary; //width/2 or length/2, whichever is smaller
for(depth while depth is less than the upper boundary, increasing depth by 0.01 each time)
   find out volume at this value of depth
   if this volume < volumevariable then break;
   otherwise set the volumevariable to the current volume and keep looping

subtract 0.01 from the depth to account for breaking out of the loop 1 iteration too late
you now have your depth value.
Your professor sounds like an idiot.
"if you think its hard i give you harder assignment"-Professor Trinh idk why he wanted us to use a different method...he said it was too easy
Use the Newton-Raphson method on the function in order to find the minimum.

Also, speed is the least of your concerns when it comes to programming. What is important is concise, readable, and extensible/reusable code. Optimization comes second (see premature optimization).
Posts 16–18 of 18 · Page 2 of 2

Post a Reply

Similar Threads

Talk with us