April 29th, 2015, 01:09 AM
A simple math problem with PHP
I had asked the similar thing before.
I want to come up with a formula that calculates width, length and height based on the ratio.
The ratio is 0.63 which is very simple:
So to calculate these values based on the volume of a rectangular tank (which is 83 cubic inch ) I thought:
width = height = length/0.63
But I don't get correct results. It's very off! I get
I am looking for bbc5f715bcd97caec4c79ff949a8fa1a6419cfaf54.png
$dimentions['width'] = $dimentions['height'] = round(pow(83/3,0.63)) ;
$dimentions['length'] = $dimentions['width']/(0.63);
What am I doing wrong lord?
Last edited by English Breakfast Tea; April 29th, 2015 at 02:00 AM.
April 29th, 2015, 02:37 AM
So... the end face of the rectangular prism is square (width = height) and the each of those is the length / 0.63 (that is, roughly 1.5 times longer)?
width * height * length = volume
width = height = A
A * A * length = volume
A = length / 0.63
A * 0.63 = length
A * A * A * 0.63 = volume
A**3 * 0.63 = volume
A**3 = volume / 0.63
A = (volume / 0.63) ** (1/3)
$width = $height = pow($volume / 0.63, 1/3);
$length = $width * 0.63;
April 29th, 2015, 02:41 AM
Originally Posted by requinix
This works better:
My problem (well, main one) was not knowing how to use pow properly.
April 29th, 2015, 03:23 AM
But that's not what you described. And you're rounding too early: the length should be calculated using the original, unrounded value of the width (or height).
April 30th, 2015, 06:56 AM
So, is the response your equation is offering you close to the following?
When standing in front of a tank...
Length: 5.95 (The longer measurement, left to right)
Width: 3.7485 (Depth, front to back)
Height: 3.7485 (Top down)
This offers the .63 ratio on the longer, not square, faces of your tank, and comes just a hair over the 83 for your volume.
Would these be (or close to, if rounding) the numbers you wish your equation to hit? Or were we aiming something else? If something else, and the answer has not been achieved, can you manually calculate what you wish your code to achieve, and let us know?
I'm kinda lost as to the use of the 1/3 power. Unless we're each drawing this tank a little differently in our heads...
He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
April 30th, 2015, 08:03 AM
If you write the volume in terms of the width (for example), you end up with width * width [because width = height] * width / 0.63 [the length] = volume. That rearranges to width ** 3 = 0.63 * volume, thus width = third root of (0.63 * volume). And the Nth root of a thing is equivalent to the thing raised to the power 1/N.
Originally Posted by Triple_Nothing
Testing with your numbers, 83 * 0.63 = 52.29, third root of that is 3.7394. Which should be a little less than your values due to the "just a hair over the 83" bit.
Comments on this post