Cube Root

HalloJulle

Member
Join Date
May 2008
Location
Vanderbijlpark
Posts
12
I need to calculate the value of currents on the secondary side of a transformer wired in Delta configuration. I am able to do the calculation but now need to get the cube root value for the Delta connection. The PLC does not have a function to do straightforward cube root calculation so I would appreciate some help on this.
 
I need to calculate the value of currents on the secondary side of a transformer wired in Delta configuration. I am able to do the calculation but now need to get the cube root value for the Delta connection. The PLC does not have a function to do straightforward cube root calculation so I would appreciate some help on this.
Roots are fractional powers if that can help you. If the PLC has no power function but logarithms are available, you can work with those too.

Kind regards,
 
We can't be of much help if you don't say what PLC you are using. With an Allen-Bradley SLC, you can use the XPY instruction with a Y value of 0.333 to get a cube root.
 
Why is the cube root involved in this calculation? Are you sure it's not the Square root of 3 (1.7321) you need?
rmb
 
Why is the cube root involved in this calculation? Are you sure it's not the Square root of 3 (1.7321) you need?
rmb
Why spoil our fun? :mad: If the OP wants a cube root, we'll give him a cube root. You never know who might be helped with it.

Regards,
 
This is another example of the asking the wrong question but

You never know who might be helped with it.
What is interesting is that L D [AR2,P#0.0]'s iterative method converges quickly requiring fewer iterations that the traditional Newton's method. L D [AR2,P#0.0]'s method is very good if one can't make a good guess for the cube root.

I have a method that is very fast. It makes a good estimate for the cube root by manipulating the exponent directly. Only one division is required for all iterations. This is important because one divide takes about 35-40 clocks cycles to 1 for a multiply and add so I can do all five iterations in the time one can do one using L D [AR2,p#0.0]'s method.

An iteration looks like this
r = r*(FourThirds-r*r*r*inv3a);
which is much simpler and faster than what L D [AR2,p#0.0] posted but it doesn't converge in as few iterations so a good first estimate is required.

On real CPUs a multiply may take 1 or 2 clock cycles whereas a floating point divide is still done using Newton's method too or perhaps the shift and subtract method. It is best to avoid divides when coding for speed. Multiplies don't suffer from divide by 0 error either.

This is a case where the S7 would shines because it allows lower level access to the data in the accumulators.

The XPY method should only be used it there is CPU power to waste.
 
r = r*(FourThirds-r*r*r*inv3a);

I would assume he means inverse. So something like this:
r = r * (4/3 - r^3 * 1/3a);

Meaning r = r times ( four thirds minus r cubed times one third a)

where a is an approximation of the cube root, and r is a closer approximation of the cube root.
 
r*r*r, not r^3. To you and I they are the same thing, but to a computer they are not even close. r*r*r is fast and easy. r^3 is not.
 
lol, I did that for clarity. Also, if there is an optimizer checking the code, r^3 would simplify to r*r*r anyway (unless there's an even quicker way to do it).

I'm aware of the difference to a computer when it comes to multiplication vs exponentiation (is that a word?). I'm also aware that in anything but a rudimentary compiler, everything that you write gets mangled all to hell and optimized into something much more efficient, at the cost of occasionally being completely different than what you originally wrote.

I was trying to make it a bit easier for someone to read, rather than optimizing it for a PLC. If I was optimizing it for a PLC, i'd have replaced 4/3 with 1.333... (or however many decimal places it's possible to define), and 1/3 to 0.333...
 
Bobbias has it right!!!!

inv3a is 1/3a where a is the number I want to take the cube root of. Also, any decent compiler will convert r^3 to r*r*r.
r^4 gets coverted to
temp=r*r
ans=temp*temp
so there is only still only two muliplies.
(4/3) should compile to 1.333333 instead of 4/3.
Bobbias, good insight.
Alaric, our compiler converts intger powers to simple mulitplies becase multiplies happen in one clock cycle and we are fantical about speed.
 
Here's some results for the two algorithms (DB3=Peter's
Algorithm). I used unity as the initial guess.

cuberoot.jpg
 
It is very interesting to discuss technical nuts and bolts of various algorithms and their efficiencies but how about this one for X^Y

Code:
      L     #rXvalue
      LN    
      L     #rPowerN
      *R    
      EXP   
      T     #rTemp

Nick

Current location: cold and miserable in China
 

Similar Topics

Hello, I was looking for alternatives to using the standard AB Local IO and I came across the Cube 20 series from Murr. I know the response...
Replies
10
Views
2,213
Don’t waste your time trying to solve the Rubik's Cube. It can now solve itself. https://www.youtube.com/watch?v=2PGjTt4xkWM&t=2s
Replies
6
Views
2,842
Can anyone elaborate on the differences on how these technologies work? It sounds similar, but IO Link adds the addition of sending parameters to...
Replies
6
Views
3,170
This is not really a plc question but I am sure for many of you this will be a simple question to answer. I have an old machine that has several...
Replies
5
Views
2,427
Hi, we have a small machine that sends parts from hopper to conveyor line. It uses Rodix Feeder Cubes as a controller for a DC agitator/vibrator...
Replies
0
Views
1,595
Back
Top Bottom