Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plotting Help Needed
#1
Hey everyone, so I'm generating nxn matrices where n ranges from 1 to 100 and I have made it such that the matrix is symmetric. I'm computing the average eigen value for each nxn matrix and then I want to loop that 100 times such that I will get an average of my average eigenvalue for each nxn matrix.

I then want to plot n vs the average eigen value found for that corresponding n. However, in my code currently nothing is plotted and it appears to be generating a plot for each averaging iteration? My code is listed as below and any help would be greatly appreciated!!

import numpy as np
import random
import matplotlib.pyplot as plt

for j in range(100):
    mat1x1 = np.random.uniform(-1,1,(1,1))
    mat1x1_eig = np.linalg.eig(mat1x1)
    d = sum(mat1x1_eig)
    e = d - 1
    print(f"1x1 eig : {mat1x1_eig}")
    'I dont know why my array is adding 1 so e is a correctional term to get the proper lamda_1 eigen value'
    print(f"1x1 eig avg : {e}")


    for size in range(2,101):
        mat = np.random.uniform(-1,1,(size,size))
        
        'random.uniform draws a sampling from a uniform distrobution'
        
        mat1 = np.tril(mat)+np.tril(mat,k=-1).T 
        
            
        'tril returns copy of array with kth diagonal zeroed and the above array elements'
        
        diagonal_avg = sum(np.diag(mat1))/size
        
        'lamda_avg returns the average diagonal value of matrix (sum of diagonals/size "n" of matrix'
    
        'needed to add this if else statement to correctly get an eigenvalue for 1x1 matrix'
        mat1_eig = np.linalg.eig(mat1)
        
        b = sum(np.linalg.eig(mat1))
        c = np.average(b)
       
        lamda_avg = c 
        'c is the average eigen value for lamda_n'
        
        'trying to work with tuple for averaging purpose'
       
        delta_lamda = c - e
        
            
        'important part of the code that gives me my average delta lamda value for lamda_n - lamda_1 eigen values'
        
        print(f"delta_lamda : {delta_lamda}")
       
    
        'lamda_size = mat1_eig - a'
        'print(lamda_size)'
        
        'need to create a function for "delta_lamda" such that it = (lamda_n - lamda_1)/(n-1)'
    plt.plot(size, delta_lamda)
    plt.show()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020