Wie passen Sie mit Python [Duplikat] auf Daten an.Python

Python-Programme
Anonymous
 Wie passen Sie mit Python [Duplikat] auf Daten an.

Post by Anonymous »

Entschuldigung, dass Sie Fragen mit niedrigem Niveau gestellt haben. Ich bin Physiker und ich weiß nicht viel über das Programmieren
Ich habe Daten, die es mit Probolic anpassen möchten, und ich habe keine Lösung, um sie zu lösen. /> y < /th>
z < /th>
T < /th>
< /tr>
< /thead>


-2.647448112689693E-5< />-0.001207315269806859
0.002531873588394084
287.67551366492546< />-2.7110000000000003E-5
-0.00122208
0.00259646000000000055
< />
-2.6242756278597524e-5
-0.0012018372028238663 0.00250791568924251,/tdd> < />287.70800576511095



Also möchte ich x und t
Orginalcode < /h3>

Code: Select all

from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

# Define the Gaussian function
def Gauss(x, A, B):
y = A*np.exp(-1*B*x**2)
return y
def parabola(x, a,b, c):
return a*(x**2) - c

xdata = [ -10.0, -9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
ydata = [1.2, 4.2, 6.7, 8.3, 10.6, 11.7, 13.5, 14.5, 15.7, 16.1, 16.6, 16.0, 15.4, 14.4, 14.2, 12.7, 10.3, 8.6, 6.1, 3.9, 2.1]

xdata = np.asarray(xdata)
ydata = np.asarray(ydata)
plt.plot(xdata, ydata, 'o')

parameters, covariance = curve_fit(parabola, xdata, ydata)

fit_A = parameters[0]
fit_B = parameters[1]
fit_c =parameters[2]

fit_y = parabola(xdata, fit_A, fit_B,fit_c)
plt.plot(xdata, ydata, 'o', label='data')
plt.plot(xdata, fit_y, '-', label='fit')
plt.legend()
< /code>
Ausgabe < /p>
Ich habe also ein kleines Bit geändert, um Daten aus meiner Datei abzurufen, und es funktioniert jetzt nicht
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import os
path = os.path.join(os.getcwd(),"Temp.txt")
f_t = open(path, 'r')

def get_3data(f):
X=[];Y=[];Z=[];T=[]

for i in f.readlines():
x,y,z,t =i.split()
X.append(float(x))
Y.append(float(t))

f.close()
return X,Y
xarray,yarray = get_3data(f_t)

def fit_probolic(xdata,ydata):

def parabola(x, c,a):
return c-a*(x**2)
#sort data
L = sorted(zip(xdata,ydata))
xdata, ydata = zip(*L)
xdata=np.array(xdata)
ydata=np.array(ydata)

parameters, covariance = curve_fit(parabola, xdata, ydata)

fit_A = parameters[0]
fit_B = parameters[1]
print('n0 = ', fit_A)
print('n2 = ',fit_B)
fit_y =parabola(xdata, fit_A,fit_B)
plt.plot(xdata, ydata, 'o', label='data',linewidth=0.1)
plt.plot(xdata, fit_y, '-', label='fit',linewidth=2)
plt.legend()
plt.show()

fit_probolic(xarray,yarray)

Ausgabe
Erwartung Ausgabe

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post