I have successfully discovered the method to write algorithm for Collatz Conjecture and to find area using Simpson’s numerical method. But my problem is I cannot combine these program. I have trouble in storing the generated numbers under “while” loop.
How to store the list of numbers (like 8,4,2,1) to np.array() such that is produces area output
from __future__ import print_function import numpy as np from scipy.integrate import simps from numpy import trapz n=int(input("Enter the Number ")) count=0 a=0 a=n while(n!=1): if(n%2==0): n=n//2 print(n,'\n') count=count+1 else: n=3*n+1 print(n,'\n') count=count+1 y1 = np.array([n]) #This abve line should be corrected I believe print("Collatz for ",a," count is ",count) # Compute the area using the composite Simpson's rule. area = simps(y1, dx=1) print("area for Collatz",a,"=", area)