Re: Using '__mul__' within a class



>>>>> James Stroud <jstroud@xxxxxxxxxxxx> (JS) wrote:

>JS> def Multiply(self, other):
>JS> self.a = self.a * other.a + self.b * other.b
>JS> self.b = self.a * other.b + self.b * other.c
>JS> self.c = self.b * other.b + self.c * other.c

I gues this will give the wrong result because the calculation of self.b is
supposed to use the original value of self.a, not the newly calculated one.
Similar for self.c. The following should do that:

self.a, self.b, self.c = (self.a * other.a + self.b * other.b,
self.a * other.b + self.b * other.c,
self.b * other.b + self.c * other.c)
--
Piet van Oostrum <piet@xxxxxxxx>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet@xxxxxxxxxxxxxx
.



Relevant Pages

  • Re: Protecting against callbacks queuing up?
    ... - the event should be an argument to the doCallback thinghy too, ... so that you can get at what you need to do the calculation. ... def data_callback: ... see above - just clear it from the called routine. ...
    (comp.lang.python)
  • Re: Bytes/File Size Format Function
    ... import math ... def filesizeformat: ... The output doesn't match the calculation. ...
    (comp.lang.python)
  • SUM or COUNT and adding a row
    ... same and the one row will be missing from the calculation. ... How could I resolve it and give the user the flexibility to add a row the ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • RE: how do I test for Integer?
    ... > I wish to test if the results of a calculation is an integer. ... An unknown ... > function perhaps in the stats package? ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Nested IF(AND is not working
    ... >my goal is tot have the following for statements placed in a cell via this ... >calculation to cover 4 possible variables. ... >Thanks Todd Frisch tfrisch9@xxxxxxxxxxx ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)