How can this assert() ever trigger?

Albert van der Horst albert at spenarnc.xs4all.nl
Tue May 13 05:56:00 EDT 2014


In article <mailman.9917.1399914607.18130.python-list at python.org>,
Joseph Martinot-Lagarde  <joseph.martinot-lagarde at m4x.org> wrote:
>Le 10/05/2014 17:24, Albert van der Horst a écrit :
>> I have the following code for calculating the determinant of
>> a matrix. It works inasfar that it gives the same result as an
>> octave program on a same matrix.
>>
>> / ----------------------------------------------------------------
>>
>> def determinant( mat ):
..
>>      result = lastr[jx]
>>      assert(result<>0.)
...
>>          assert(result<>0.)
>>          nom *= result   # Compenstate for multiplying a row.
...
>>      assert(nom<>0.)
..
>>
>> /-----------------------------------------
>>
>> Now on some matrices the assert triggers, meaning that nom is zero.
>> How can that ever happen? mon start out as 1. and gets multiplied
>> with a number that is asserted to be not zero.
>>
>> Any hints appreciated.
>>
>> Groetjes Albert
>>
>I know it's not the question, but if you want a replacement for octave
>did you try numpy (and scipy) ? The determinant would be computer faster
>and with less memory than with your function.

I'm using several programming languages in a mix to solve Euler problems.
This is about learning how octave compares to python for a certain kind of
problem as anything.
The determinant program I had lying around, but it was infinite precision
with integer only arithmetic. Then I made a simple modification and got
mad because I didn't understand why it didn't work.

I have used numpy and its det before, but I find it difficult to
remember how to create a matrix in numpy. This is the kind of thing
that is hard to find in the docs. Now I looked it up in my old
programs: you start a matrix with the zeroes() function.

I expect the built in determinant of octave to be on a par with corresponding
python libraries.

>
>---

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list