Description In this assignment we will implement the method of Least Squares fitting using a python script.
Question:
Description
In this assignment we will implement the method of Least Squares fitting using a python script. For matrix routines, you may choose to use the linear algebra library routines in the numpy library, you may also use routines from this library which I wrote or you may wish to write your own routines. I like to write my own because I am too lazy to learn how to use those others have written!
Your program should do the following:
take a commandline argument that specifies a data file containing the data to be fitted. Sample data file
if this argument is not provided by the user, the program should prompt the user for a file
Read the data file and create the required matrices and vectors to perform the fit
Utilize matrix inversion and multiplication routines to perform the fit
Report the results including
obscalc for each data point
the values of the adjustable parameters
including their uncertainties
the standard deviation of the fit.import numpy as npimport matplotlib.pyplot as pltfrom scipy.fft import fft ifft# Define singlescansinglescan nprandom.normal # Single scandef fouriersmoothingdata cutoff: ftsignal fftdata ftsignalfiltered ftsignal.copy ftsignalfilteredcutoff: # Apply lowpass filter smoothedsignal nprealifftftsignalfiltered return smoothedsignalcutofffreqs # Example cutoff frequenciesplt.figurefigsizepltplotsinglescan, label'Original Signal'for cutoff in cutofffreqs: smoothedsignal fouriersmoothingsinglescan, cutoff pltplotsmoothedsignal, labelf'Cutoff Frequency: cutoffpltxlabelData Points'pltylabelIntensityplttitleFourier Transform Smoothing'pltlegendpltshow
John E Freunds Mathematical Statistics With Applications
ISBN: 9780134995373
8th Edition
Authors: Irwin Miller, Marylees Miller