Question: Mechanical Spring Deflection Some tests are run where a ball of a fixed mass dropped from a known height to land inelastically onto a spring
Mechanical Spring Deflection
Some tests are run where a ball of a fixed mass dropped from a known height to land inelastically onto a spring whose maximum compression is recorded. The data collected from tests runs at several heights will be contained in a text file in the same folder as your Matlab code called CompressionVersusHeight.txt an example of which is available on CatCourses. Note that the data file can have any number of data points after the three header lines and any script that reads it must be able to read different versions without change to the script. A plot of the example data is shown.
Write a singlefile Matlab script that reads the data from CompressionVersusHeight.txt Then, use Matlab's curvefitting function to find a curve of the form xA sqrth that best fits the data. Make sure that your code assigns the value of the value of A to a variable called A On a single figure, plot the original data with markers and the fitted curve on the same plot, with a legend, appropriate axis labels and indicate clearly in the plot title the value obtained for A with four digits after the decimal place.
Hint: This is most easily done using the custom curve fit technique discussed in the lecture notes.
A sample of the resulting plot for a slightly different data set is shown below. Write a singlefile Matlab script that reads the data from CompressionVersusHeight.txt Then, use Matlab's curvefitting function to find a curve of the form xA sqrth that best fits the data. Make sure that your code assigns the value of the value of A to a variable called A On a single figure, plot the original data with markers and the fitted curve on the same plot, with a legend, appropriate axis labels and indicate clearly in the plot title the value obtained for A with four digits after the decimal place.
Hint: This is most easily done using the custom curve fit technique discussed in the lecture notes.
A sample of the resulting plot for a slightly different data set is shown below.
nata with mathbfxboldsymbolDelta cart h curve fit
Read the data from the file
data readmatrixCompressionVersusHeighttxt 'NumHeaderLines', ;
Extract height h and compression x from the data
h data:;
x data:;
Define the curve fitting model
model fittypeA sqrth 'independent', h 'coefficients', A;
Perform the curve fitting
startPoint ;
fitResult fith x model, 'StartPoint', startPoint;
Extract the coefficient A
A fitResult.A;
Generate the fitted curve for plotting
fittedx A sqrth;
Create the plot
figure;
ploth xgx 'DisplayName', 'Data'; Original data points
hold on;
ploth fittedxb 'DisplayName', 'Fit'; Fitted curve
hold off;
Add labels, legend, and title
xlabelHeight h m;
ylabelCompression x m;
legendshow;
titlesprintfData with x A sqrth curve fit
A f A;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
