-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
welcome=""" | ||
#*#*#*#*#*#*#*#*#**#*#*#*#**#*#*#*#**#*#*#*#*#*#**#*#*#*#**#*#*#*#**#*# | ||
#* #* | ||
#* Curve Fitting #* | ||
#* By #* | ||
#* Least Square Method #* | ||
#* Find the Exponential Curve that BEST fits for your data #* | ||
#* Credit- Monirul Shawon #* | ||
#* #* | ||
#*#*#*#*#*#*#*#*#**#*#*#*#**#*#*#*#**#*#*#*#*#*#**#*#*#*#**#*#*#*#**#*# | ||
""" | ||
print(welcome) | ||
|
||
import numpy as np | ||
import math | ||
from tabulate import tabulate | ||
x=[] | ||
y=[] | ||
try: | ||
n=int(input("How many number of sets you've got there? \n n= ")) | ||
print('-'*70) | ||
print("Let, y=ae^(bx) or Y=A+Bx where Y=log10(y) , A=log10(a) and B=blog10(e) ") | ||
print('-'*70) | ||
#taking x values | ||
print("\nInput values of x: ") | ||
for i in range(1,n+1): | ||
xnum=float(input(f" x{i} = ")) | ||
x.append(xnum) | ||
#taking y values | ||
print("\nInput values of y:") | ||
for j in range(1,n+1): | ||
ynum=float(input(f" y{j} = ")) | ||
y.append(ynum) | ||
#making x square row | ||
squarex=[a*a for a in x] | ||
#making Y=log10(y) row | ||
Y=[math.log10(b) for b in y] | ||
#making x*y row | ||
multi=[a*b for a,b in zip(x,Y)] | ||
#table | ||
table=[(p,q,r,s,t) for p,q,r,s,t in zip(x,y,Y,squarex,multi)] | ||
headers=['x','y','Y=log10(y)','x^2','xY'] | ||
print(tabulate(table,headers,tablefmt="pretty")) | ||
#table summation | ||
sumx=sum(x) | ||
sumy=sum(y) | ||
sumY=sum(Y) | ||
sumsquarex=sum(squarex) | ||
sumxY=sum(multi) | ||
#table2 | ||
table2=[(sumx,sumy,sumY,sumsquarex,sumxY)] | ||
headers2=['∑x','∑y','∑Y','∑x^2','∑xY'] | ||
print(tabulate(table2,headers2,tablefmt="pretty")) | ||
|
||
print(f"\nEquation 1 is: {sumY} = {n} A + {sumx} B") | ||
print(f"Equation 2 is: {sumxY} = {sumx} A + {sumsquarex} B") | ||
#solve liner equations | ||
M=np.array([[n,sumx],[sumx,sumsquarex]]) | ||
N=np.array([sumY,sumxY]) | ||
X=np.linalg.solve(M,N) | ||
#solve a and b | ||
a=math.pow(10,X[0]) | ||
b=X[1]/(math.log10(math.e)) | ||
print(f"Hence, the required curve is: y={a} e^({b} x)") | ||
except: | ||
print("\nNo.. input is not a number. It's a string.") | ||
print("Please input number to continue your calculation") |