Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Why does my code run in Jupyter and in Spyder but not in PyCharm? When I run this same code in PyCharm, I get an
Why does my code run in Jupyter and in Spyder but not in PyCharm?
When I run this same code in PyCharm, I get an error saying, "OptimizeWarning: Covariance of the parameters could not be estimated."
If there a reason why there is an issues with running the code and how I can fix it in PyCharm?
import numpy as np import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt from scipy.optimize import curve_fit time, position, uncertainty = np.loadtxt('/Users/ryanapanela/OneDrive/Documents/Second Year/PHY224/Introduction to Scientific Computing/feather.txt', unpack=True) print('Time (h): ' +str(time), 'Position (m): ' +str(position), 'Uncertainty (m): ' +str(uncertainty)) def h_prediction(time, h0, speed, acceleration): return h0 + (speed*time) + (1/2)*(acceleration)*(time**2) g = (1/7)*9.81 popt, pcov = curve_fit(h_prediction, time, position, absolute_sigma=True, sigma=uncertainty, p0=[2,0,g]) pstd = np.sqrt(np.diag(pcov)) print('Initial Height = ' +str(popt[0]), 'm') print('Speed = ' +str(popt[1]), 'm/s') print('Acceleration = ' +str(popt[2]), 'm/s^2') print('Standard Deviation of Initial Height = ' +str(pstd[0]), 'm') print('Standard Deviation of Speed = ' +str(pstd[1]), 'm/s') print('Standard Deviation of Acceleration = ' +str(pstd[2]), 'm/s^2') plt.plot(time, h_prediction(time, popt[0], popt[1], popt[2]), label = 'Curve of Best Fit') plt.errorbar(time, position, yerr=uncertainty*2, linestyle='', marker='o', label='Recorded Data') plt.xlabel('Time (h)') plt.ylabel('Position (m)') plt.title('Height of Feather vs. Time') plt.legend() plt.show()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started