Author Topic: -={ Challenge }=- Matrix Determinant  (Read 14276 times)

0 Members and 1 Guest are viewing this topic.

chlh_jd

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #15 on: January 26, 2011, 03:57:15 AM »
all Great !  :-o

before this , I have been use Gile's deter function , it's so fast ,Thanks Gile !
Evgeniy's fastest , Thank you !
But now I test the matrix (det-g '((1 2 3) (2 4 5) (3 5 6))) , It take wrong result  0 , not the corret -1.
« Last Edit: January 26, 2011, 04:09:18 AM by chlh_jd »

Brick_top

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #16 on: January 26, 2011, 04:40:53 AM »
The sad part is that I don't even know what this is for  :oops:

edit - even sadder is that I didn't  read the explanation in the first post

edit 2 - now that I read it I don't understand it... Unfortunately I could go on and on

sorry for the off topic
« Last Edit: January 26, 2011, 05:30:30 AM by Brick_top »

SOFITO_SOFT

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #17 on: January 26, 2011, 08:29:03 AM »
Quote
Code: [Select]
If it is necessary concise:
(defun d(l)(if l(*(caar l)(d(mapcar'(lambda(a)(mapcar'(lambda(b c)(- b(* c(/(car a)1.(caar l)))))(cdr a)(cdar l)))(cdr l))))1))
BravoooOOOO !!!  :lol:

chlh_jd

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #18 on: February 05, 2011, 08:18:09 AM »
Hi Sofito_soft
Hi ElpanovEvgeniy
Is it my PC problem ? I test the matrix '((1 2 3) (2 4 5) (3 5 6)) , however , your functions 'det-g or 'd din't give the correct result  :angel:

SOFITO_SOFT

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #19 on: February 06, 2011, 07:44:40 AM »
Hello people of the swamp:
chlh_jd:
proceedings are divisions, so the numbers to drive must be real, not integers. :|
Please try with '((1.0 2. 3.) (2. 4. 5.) (3. 5. 6.))   :-o
Greetings. :-)

SOFITO_SOFT

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #20 on: February 06, 2011, 07:54:10 AM »
Hello people of the swamp:
chlh_jd:
not all determinants also has a solution!
For example, if 2 lines are dependent, can not be resolved.
((1 2 3) (3 6 9 ).....) has no solution because (1 2 3) x 3 = (3 6 9). They are dependent! ;-)
There are more cases that has no solution.  :oops:
Greetings  :-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Matrix Determinant
« Reply #21 on: February 06, 2011, 08:40:09 AM »
Hello people of the swamp:
chlh_jd:
not all determinants also has a solution!
For example, if 2 lines are dependent, can not be resolved.
((1 2 3) (3 6 9 ).....) has no solution because (1 2 3) x 3 = (3 6 9). They are dependent! ;-)
There are more cases that has no solution.  :oops:
Greetings  :-)

It seems to me that in these cases the routine have to return 0.0.

Anyway, here's another solution using Gauss pivot (the matrix determinant is equal to the product of all the pivots used in a Gauss-Jordan elimination)
This method should be much more faster with large dimension matrices.

Code: [Select]
(defun gc:determ (mat / col piv row res det)
  (setq res 1.)
  (while (< 2 (length mat))
    (setq col (mapcar '(lambda (x) (abs (car x))) mat))
    (repeat (vl-position (apply 'max col) col)
      (setq mat (append (cdr mat) (list (car mat))))
    )
    (if (equal (setq piv (float (caar mat))) 0.0 1e-13)
      (setq mat nil
    res 0.0
      )
      (setq row (mapcar '(lambda (x) (/ x piv)) (car mat))
    mat (mapcar
  '(lambda (r / e)
     (setq e (car r))
     (cdr (mapcar '(lambda (x n) (- x (* n e))) r row))
   )
  (cdr mat)
)
    res (* piv res)
      )
    )
  )
  (setq det (- (* (caar mat) (cadadr mat)) (* (caadr mat) (cadar mat))))
  (if (equal 0. det 1e-14)
    0.
    (* res det)
  )
)
« Last Edit: February 06, 2011, 01:01:21 PM by gile »
Speaking English as a French Frog

SOFITO_SOFT

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #22 on: February 06, 2011, 03:14:40 PM »
Indeed Gille:
not all determinants also has a solution! <<<< with the LSP program....
For example, if 2 lines are dependent, can not be resolved <<<< with the LSP program....
As you say, should return 0
Regards.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Matrix Determinant
« Reply #23 on: February 06, 2011, 03:32:34 PM »
Indeed Gille:
not all determinants also has a solution! <<<< with the LSP program....
For example, if 2 lines are dependent, can not be resolved <<<< with the LSP program....
As you say, should return 0
Regards.

Did you try all the upper routines with: '((1. 2. 3.) (3. 6. 9.) (7. 5. 3.)) for example ?
All resolve the problem returning 0.0
Speaking English as a French Frog

chlh_jd

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #24 on: February 09, 2011, 11:02:52 AM »
Hi  SOFITO_SOFT
I've test in real , it take a wrong result yet .
Hi All ,
How to invers this matrix :
Code: [Select]
'((7.0 0.0 -3.0 2.0 0.0 -4.0 -4.0 2.0) (0.0 13.0 2.0 -1.0 -4.0 0.0 2.0 -12.0)
(-3.0 2.0 7.0 -4.0 -4.0 2.0 0 0) (2.0 -1.0 -4.0 13.0 2.0 -12.0 0 0) (0.0 -4.0
-4.0 2.0 7.0 0.0 -3.0 2.0) (-4.0 0.0 2.0 -12.0 0.0 13.0 2.0 -1.0) (-4.0 2.0 0 0
-3.0 2.0 7.0 -4.0) (2.0 -12.0 0 0 2.0 -1.0 -4.0 13.0))
It's a matrix of a cantilever beam  for Finite element analysis , It can be inversed by 'MatLab' .
However , all above codes returns nil or 0.0 ?
Therefore, is there some way to use scientific notation to represent  intermediate values or  results ?
« Last Edit: February 09, 2011, 11:12:43 AM by chlh_jd »

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: -={ Challenge }=- Matrix Determinant
« Reply #25 on: February 09, 2011, 02:02:36 PM »
Please stop - you're all scaring me!  :|

 :lol:
James Buzbee
Windows 8

SOFITO_SOFT

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #26 on: February 10, 2011, 03:49:56 PM »
glubssss ....I do not get to much .... I use "Calc3D ".....
greetings

chlh_jd

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #27 on: February 15, 2011, 12:27:41 AM »
Excellent Gile !
Thank you for your Gauss Way determent fun .

chlh_jd

  • Guest
Re: -={ Challenge }=- Matrix Determinant
« Reply #28 on: February 15, 2011, 12:31:45 AM »
Is it can change a lit ? Because it will get a null 'mat' in some case , E.G. the matrix in 'Reply #25 on' .
Quote
Code: [Select]
(setq det (- (* (caar mat) (cadadr mat)) (* (caadr mat) (cadar mat))))
Code: [Select]
(if mat (setq det (- (* (caar mat) (cadadr mat)) (* (caadr mat) (cadar mat)))) (setq det 0.0))
« Last Edit: February 15, 2011, 12:34:48 AM by chlh_jd »

ribarm

  • Gator
  • Posts: 3263
  • Marko Ribar, architect
Re: -={ Challenge }=- Matrix Determinant
« Reply #29 on: December 18, 2019, 06:30:34 PM »
I've added my new version here :
http://www.theswamp.org/index.php?topic=45666.msg597622#msg597622

Regards, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube