Author Topic: How to Get Eigenvalues ​​and Eigenvectors of the matrix ?  (Read 18975 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3258
  • Marko Ribar, architect
Re: How to Get Eigenvalues ​​and Eigenvectors of the matrix ?
« Reply #30 on: December 26, 2019, 05:25:12 AM »
Maybe I have to firstly normalize matrix, like this user wanted to explain :
https://mymathforum.com/threads/how-do-i-normalize-a-matrix.18218/#post-159640

And then multiply matrix ~ 40 times to get all rows the same (row=eigenvector)... Of course eigenvalue should have it's purpose, so I suppose that matrix for multiplication should be : mat-mat[E] - just guessing

Something like this was shown at the bottom of page I already mentioned :
https://www.intmath.com/matrices-determinants/8-applications-eigenvalues-eigenvectors.php

Now the question : How to normalize matrix with elements - complex numbers?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3258
  • Marko Ribar, architect
Re: How to Get Eigenvalues ​​and Eigenvectors of the matrix ?
« Reply #31 on: December 26, 2019, 05:53:01 AM »

Maybe I have to firstly normalize matrix, like this user wanted to explain :
https://mymathforum.com/threads/how-do-i-normalize-a-matrix.18218/#post-159640

And then multiply matrix ~ 40 times to get all rows the same (row=eigenvector)... Of course eigenvalue should have it's purpose, so I suppose that matrix for multiplication should be : mat-mat[E] - just guessing

Something like this was shown at the bottom of page I already mentioned :
https://www.intmath.com/matrices-determinants/8-applications-eigenvalues-eigenvectors.php

Now the question : How to normalize matrix with elements - complex numbers?


I just realized that this path is wrong, but I searched for answers, so nothing wrong...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3258
  • Marko Ribar, architect
Re: How to Get Eigenvalues ​​and Eigenvectors of the matrix ?
« Reply #32 on: August 17, 2020, 03:11:11 PM »
Since no one really knew how to steer me in right direction, I decided to try once more time my way... I don't know if I am right or wrong, but I don't like to leave problems unsolved, at least to the point we see some tangible results... To get my point and confirm if I am right or wrong I strongly suggest that you read complete comment to understand what's going on... So here is my latest attempt I hope with some sense... I know that someone would say : "Hey this is absurd...", but nevertheless I leave that to others to judge...

Code - Auto/Visual Lisp: [Select]
  1. (defun [V] ( [E] mat / detmc trp cxc c-c c_ c/c A-[E]I matn v matn-1 det detx x k kk kkk n nn )
  2.  
  3.   ;;;***********************************************************************************;;;
  4.   ;;; (detmc m) function calculates determinant of square martix                        ;;;
  5.   ;;; this version includes complex numbers                                             ;;;
  6.   ;;; Marko Ribar, d.i.a.                                                               ;;;
  7.   ;;; Args: m - nxn matrix of complex numbers                                           ;;;
  8.   ;;; (detmc '(((0 0) (1 0)) ((1 0) (0 0))))                                            ;;;
  9.   ;;; (detmc '(((1.4 0) (2.1 0) (5.4 0) (6.5 0)) ((4.1 0) (9.3 0) (4.5 0) (8.5 0)) ((1.2 0) (4.1 0) (6.2 0) (7.5 0)) ((4.7 0) (8.5 0) (9.3 0) (0.1 0))))                                                                                 ;;;
  10.   ;;;***********************************************************************************;;;
  11.  
  12.   ;;; Command: (detmc '(((1.2 1.0) (2.4 1.3) (0.5 0.6)) ((1.3 1.25) (1.5 2.0) (0.8 -1.4)) ((-2.3 -1.4) (0.6 -0.6) (-0.3 -0.3))))
  13.   ;;; (-15.3785 7.4325)
  14.  
  15.   ;;; det = (1.2 + 1.0i)(1.5 + 2.0i)(-0.3 - 0.3i)+(2.4 + 1.3i)(0.8 - 1.4i)(-2.3 - 1.4i)+(0.5 + 0.6i)(1.3 + 1.25i)(0.6 - 0.6i)-(-2.3 - 1.4i)(1.5 + 2.0i)(0.5 + 0.6i)-(0.6 - 0.6i)(0.8 - 1.4i)(1.2 + 1.0i)-(-0.3 - 0.3i)(1.3 + 1.25i)(2.4 + 1.3i)
  16.   ;;; det = (1.8 + 2.4i + 1.5i - 2)(-0.3 - 0.3i)+(1.92 - 3.36i + 1.04i + 1.82)(-2.3 - 1.4i)+(0.65 + 0.625i + 0.78i - 0.75)(0.6 - 0.6i)-(-3.45 - 4.6i - 2.1i + 2.8)(0.5 + 0.6i)-(0.48 - 0.84i - 0.48i - 0.84)(1.2 + 1.0i)-(-0.39 - 0.375i - 0.39i + 0.375)(2.4 + 1.3i)
  17.   ;;; det = (-0.2 + 3.9i)(-0.3 - 0.3i)+(3.74 - 2.32i)(-2.3 - 1.4i)+(-0.1 + 1.405i)(0.6 - 0.6i)-(-0.65 - 6.7i)(0.5 + 0.6i)-(-0.36 - 1.32i)(1.2 + 1.0i)-(-0.015 - 0.765i)(2.4 + 1.3i)
  18.   ;;; det = 0.06 + 0.06i - 1.17i + 1.17 - 8.602 - 5.236i + 5.336i - 3.248 - 0.06 + 0.06i + 0.843i + 0.843 + 0.325 + 0.39i + 3.35i - 4.02 + 0.432 + 0.36i + 1.584i - 1.32 + 0.036 + 0.0195i + 1.836i - 0.9945
  19.   ;;; det = -15.3785 + 7.4325i
  20.  
  21.   (defun detmc ( m / d cxc det )
  22.  
  23.     (defun d ( k n / z )
  24.       (setq k (cdr k))
  25.       (setq k (apply (function mapcar) (cons (function list) k)))
  26.       (setq z -1)
  27.       (while (<= (setq z (1+ z)) (length k))
  28.         (if (= z n)
  29.           (setq k (cdr k))
  30.           (setq k (reverse (cons (car k) (reverse (cdr k)))))
  31.         )
  32.       )
  33.       (setq k (apply (function mapcar) (cons (function list) k)))
  34.       (if (= (length k) 1) (caar k) k)
  35.     )
  36.  
  37.     (defun cxc ( c1 c2 / a1 a2 b1 b2 r i )
  38.       (setq a1 (car c1) b1 (cadr c1))
  39.       (setq a2 (car c2) b2 (cadr c2))
  40.       (setq r (- (* a1 a2) (* b1 b2)))
  41.       (setq i (+ (* a1 b2) (* a2 b1)))
  42.       (list r i)
  43.     )
  44.  
  45.     (defun det ( q / i j r )
  46.       (if (not (vl-every (function numberp) q))
  47.         (progn
  48.           (setq i -1)
  49.           (setq j -1)
  50.           (setq r (list 0 0))
  51.           (foreach e (car q)
  52.             (setq i (1+ i))
  53.             (setq j (* j (- 1)))
  54.             (setq r (mapcar (function +) r (cxc (mapcar (function *) (list j j) e) (det (d q i)))))
  55.           )
  56.           r
  57.         )
  58.         q
  59.       )
  60.     )
  61.  
  62.     (det m)
  63.   )
  64.  
  65.   (defun trp ( m )
  66.   )
  67.  
  68.   (defun cxc ( c1 c2 / a1 a2 b1 b2 r i )
  69.     (setq a1 (car c1) b1 (cadr c1))
  70.     (setq a2 (car c2) b2 (cadr c2))
  71.     (setq r (- (* a1 a2) (* b1 b2)))
  72.     (setq i (+ (* a1 b2) (* a2 b1)))
  73.     (list r i)
  74.   )
  75.  
  76.   (defun c-c ( c1 c2 )
  77.     (mapcar (function -) c1 c2)
  78.   )
  79.  
  80.   ;; Complex Conjugate  -  Lee Mac
  81.   ;; Args: c1 - complex number of the form a+bi = (a b)
  82.  
  83.   (defun c_ ( c1 )
  84.     (list (car c1) (- (cadr c1)))
  85.   )
  86.  
  87.   ;; Complex Division  -  Lee Mac
  88.   ;; Args: c1,c2 - complex numbers of the form a+bi = (a b)
  89.  
  90.   (defun c/c ( c1 c2 / d )
  91.     ( (lambda ( d ) (mapcar (function (lambda ( x ) (/ x d))) (cxc c1 (c_ c2))))
  92.       (car (cxc c2 (c_ c2)))
  93.     )
  94.   )
  95.  
  96.   (defun A-[E]I ( [E] mat / k rown n matn )
  97.     (setq k -1)
  98.     (foreach row mat
  99.       (setq k (1+ k))
  100.       (setq rown (mapcar (function (lambda ( x ) (if (null n) (setq n 0) (setq n (1+ n))) (if (= n k) (cond ( (and (listp [E]) (numberp x)) (c-c (list x 0.0) [E]) ) ( (and (listp [E]) (listp x)) (c-c x [E]) ) ( (and (numberp [E]) (listp x)) (c-c x (list [E] 0.0)) ) ( t (c-c (list x 0.0) (list [E] 0.0)) ) ) (if (numberp x) (list x 0.0) x)))) row))
  101.       (setq n nil)
  102.       (setq matn (cons rown matn))
  103.     )
  104.     (reverse matn)
  105.   )
  106.  
  107.   (setq matn (A-[E]I [E] mat))
  108.   ;;; matn * v = 0 [Determinant of matn = 0 => either trivial solution of v = ((0.0 0.0) (0.0 0.0) ... (0.0 0.0)) which is not required or infinetely more solutions - system of equations is not solvable for non 0.0 values, but for parametric values...]
  109.   ;;; consider v = (x1 x2 x3 ... xn) and x1 = p + qi, then we have square matrix matn-1 (reduced first row and first column) with determinant /= 0.0 + 0.0i and corresponding augmented matrix with right column becomes x1 * v1(matn) with reduced first row and inverse signs
  110.   ;;; for easier computation reasons we now consider p = 1.0 and q = 0.0, then right column of augmented matrix becomes v1(matn) with reduced first row and inverse signs...
  111.   ;;; from this system we can calculate x2, x3, ... xn in terms of x1 = (1.0 + 0.0i) * t where t is parameter which can be any number
  112.   ;;; so here we continue...
  113.   (setq matn-1 (cdr (mapcar (function cdr) matn)))
  114.   (setq det (detmc matn-1))
  115.   (if (not (equal det '(0.0 0.0) 1e-6))
  116.     (setq k 1 kkk 1)
  117.     (progn
  118.       (setq k 0)
  119.       (while (and (equal det '(0.0 0.0) 1e-6) (<= (setq k (1+ k)) (length matn)))
  120.         (setq kkk 0)
  121.         (while (and (equal det '(0.0 0.0) 1e-6) (<= (setq kkk (1+ kkk)) (length matn)))
  122.           (setq matn-1 (vl-remove-if (function (lambda ( xx ) (if (null nn) (setq nn 1) (setq nn (1+ nn))) (if (= nn kkk) t))) (mapcar (function (lambda ( x ) (setq n nil) (vl-remove-if (function (lambda ( y ) (if (null n) (setq n 1) (setq n (1+ n))) (if (= n k) t))) x))) matn)))
  123.           (setq det (detmc matn-1))
  124.           (setq n nil)
  125.           (setq nn nil)
  126.         )
  127.       )
  128.     )
  129.   )
  130.   (if (not (equal det '(0.0 0.0) 1e-6))
  131.     (progn
  132.       (setq n nil)
  133.       (setq nn nil)
  134.       (setq kk 0)
  135.       (foreach r matn-1
  136.         (setq kk (1+ kk))
  137.         (setq detx (detmc (trp (mapcar (function (lambda ( x ) (if (null n) (setq n 1) (setq n (1+ n))) (if (= n kk) (vl-remove-if (function (lambda ( xx ) (if (null nn) (setq nn 1) (setq nn (1+ nn))) (if (= nn kkk) t))) (mapcar (function (lambda ( y ) (mapcar (function -) y))) (nth (1- k) (trp matn)))) x))) (trp matn-1)))))
  138.         (setq n nil)
  139.         (setq nn nil)
  140.         (setq x (c/c detx det))
  141.         (setq v (cons x v))
  142.       )
  143.       (setq v (reverse v))
  144.       (setq v (apply (function append) (mapcar (function (lambda ( x ) (if (null n) (setq n 1) (setq n (1+ n))) (if (= n k) (list (list 1.0 0.0) x) (list x)))) v)))
  145.     )
  146.     (progn
  147.       (prompt "\nFor all reduced square matrices (n-1 x n-1) determinant is equal to 0.0 + 0.0i, and because of this eigenvector for eigenvalue : ") (princ [E]) (prompt " and matrix : ") (princ mat) (prompt " is not possible to determine - trivial solution v = ((0.0 0.0) (0.0 0.0) ... (0.0 0.0)) is satisfactory, but not required for this task...")
  148.     )
  149.   )
  150. )
  151.  

Regards, M.R.
« Last Edit: August 20, 2020, 09:55:58 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube