Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Fix your identation?</p> <pre><code>import numpy as np import numpy.linalg import random import matplotlib.pyplot as plt import pylab from scipy.optimize import curve_fit from array import array def main(): n=20 #number of species spec=np.zeros((n+1)) for i in range(0,n): spec[i]=i t=100 #initial number of matrices to check B = np.zeros((n+1)) #matrix to store the results of how big the matrices have to be for k in range (0,t): A=np.zeros((n,n)) I=np.ones((n)) for i in range(0,n): for j in range(i+1,n): A[j,i]=random.random() for i in range(0,n): for j in range(i+1,n): A[i,j] = A[j,i] for i in range(n): A[i,i]=1 allpos = 0 while allpos !=1: #while all solutions are not positive x = numpy.linalg.solve(A,I) if any(t&lt;0 for t in x): #if any of the solutions in x are negative p=np.where(x==min(x)) # find the most negative solution, p is the position x=np.delete(x, p, 0) A=np.delete(A, p, 0) A=np.delete(A, p, 1) I=np.delete(I, p, 0) else: allpos = 1 #set allpos to one so loop is broken l=len(x) B[l] = B[l]+1 B = B/n pi=3.14 resfile=open("results.txt","w") for i in range (0,len(spec)): resfile.write("%d " % spec[i]) resfile.write("%0.6f \n" %B[i]) resfile.close() plt.hist(B, bins=n) plt.title("Histogram") plt.show() plt.plot(spec,B) plt.xlabel("final number of species") plt.ylabel("fraction of total matrices") plt.title("plot") plt.show() if __name__ == '__main__': main() </code></pre> <p>Got this:</p> <p><img src="https://i.stack.imgur.com/fzV15.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload