Answered step by step
Verified Expert Solution
Question
1 Approved Answer
## Analysis code TODO: Write a function that takes in a file name and outputs a dictionary with the values listed below - You
## Analysis code TODO: Write a function that takes in a file name and outputs a dictionary with the values listed below - You must use the names given (see json file/example in homework slide) See homework slides for further definitions/equations Check the corresponding json file and plot for the correct values ### System values (Figure 4.14 in slides) c_initial the initial position of the system (the first value) c_max - the largest position of the system (the maximum value, see Figure 4.14) c_final - the final, steady-state position of the system (the last value, see Figure 4.14) Note: For this assignment we'll just use the last value, but you could also average the last few values ### Estimate characteristics rise_time - The rise time, Tr this is the time that it takes to go from 10% to 90% of the way from c_initial to c_final (item 1 on Figure 4.14 refer to plot) The "10% time" is defined as the first time at which the system obtains a value greater than or equal to the value which is 10% between c_initial and c_final. Same with the 90% time. - peak_time - The peak time, Tp. This is the time at which the position has the maximal value (item 2 on Figure 4.14) perc_overshoot -> percentage over shoot (% OS). This is the amount that the system overshoots c_final, expressed as a percentage of the range c_initial to c_final. settling time The settling time, Ts. Estimate the 2% Settling Time, T_s. This is the earliest time when the current and all subsequent positions of the system are within a certain threshold of c_final. This threshold is defined by 2% of the range between c_initial and c_final. For example, if c_initial -1 and c_final = 1, the 2% threshold would be (0.96, 1.04) (non-inclusive of endpoints). ### Estimate model values system_mass assume the mass is 1 (this will not be true in part II) system_spring this is omega_n^2 (see slides) - system_damping - the damping term (the linear coefficient, see slides) - You may write some additional helper functions here, if you wish. Actually, I recommend writing this in pieces/multiple functions. One breakdown is the one given above calculate the values in turn. I'd suggest writing a test function for each of the group of equations above, where you test against the answers in the data1.json file (with the data1.csv file as input). I have written a general-purpose test function for you, but it tests everything all at once. markdown def analyze_data(fname): time, position = load_data_from_file(fname) length len (time) c_initial = position[0] c_max = np.max(position) c_final = position [length-1] # rise time = ten_percent c_final + 0.1*(c_max-c_final) ten_index greater_than_index (position, ten_percent) ninety_index = greater_than_index( position, (c_final - (0.1*(c_max-c_final)))) rise_time = time [ninety_index] - time[ten_index] #peak time peak_time = time [greater_than_index(position, c_max)] #overshot overshot = (c_max c_final) (c_final c_initial) *100 #setting time distance = c_final c_initial factor c_final - (0.02 *distance) #system_spring #system_damping #system mass #system_spring #system_damping #system mass my_dic = { "c_initial": c_initial, "c_max": c_max, "c_final": c_final, "rise_time":rise_time, "peak_time": peak_time, "perc_overshoot": overshot, "setting_time": T_s, # "system_spring": spring, #"system_damping": damping, # "system mass": mass } return my_dic # You must name your function this # You might also want to write some test code... def load_data_from_file(fname): data_from_csv = ts = np.loadtxt (fname, dtype="float", delimiter=",", skiprows= 1) data_from_csv[:0] vs = data_from_csv[:,1] return ts, vs 0.0s # You must name your function this def greater_than_index(in_list, in_x): for i, value in enumerate(in_list): if value >= in_x: return i return None # Tests # list [1.0, 3.0, 4.0, 7.0, 10.0], x 6.0, should give index 3 # list [ -2.5, 1.0, 4.0, 8.0, 4.0, 1.0, -2.5], x 4.0, should give index 2 # list [1.1, 2.2, 3.3, 4.4], x 5.5, should return None # # Test cases "c_initial": -1.0, "c max": 0.854459357957, "c final": -8.96706075522e-06, "rise_time": 0.01100000000000001, "peak time": 0.315, "perc_overshoot": 85.4475987155846, "settling time": 7.6, "system spring": 110.81663921393782, "system_damping": 1.0526315789473686, "system_mass": 1.0 }
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