Creating a manual fit to a plot
9 次查看(过去 30 天)
显示 更早的评论
i have a frequency data and amplitude data. i have to figure out the stiffness with the help of the resonance frequency of an freely damped oscillator. i have been asked to fit the data manually without using fit function. how can i do that ? this is my code. my plan was to create 2 plots: 1 with the ideal data and another with the constants given in the equation. and the match the graphs by changing the value of kn. as other values are known and constant
T = 300;
Q = 384.61;
f_n = 62460;
kB = 1.380648520000000e-23;
kn = 20; % initial guess
total_d_z = 1.095866243071940e-20;
frequency = linspace(total_freq(1000), total_freq(6300), 54001);
d_tot = normalized_psd(900:0.1:6300);
x = frequency;
% Define the function y
y = @(x, kn)((((2 * kB * T)./(pi * kn * f_n * Q))./((x.^2./((f_n^2)-1)).^2 + (x./(f_n^2*Q)).^2) + total_d_z^2));
% Plot the data
plot(x, d_tot, 'DisplayName', 'Measured Data', 'LineWidth', 1);
hold on;
%Plot the initial model with the initial guess for kn
plot(x,y(x, kn), 'LineWidth', 1, 'DisplayName', ['Initial Model (kn=' num2str(kn_initial) ')'],'Marker','+');
5 个评论
Harald
2024-3-9
No worries.
Often times, the full data is not needed - just a sample that sufficiently shows what's going on.
Just wanting to make sure: have you noticed the answer below?
Best wishes,
Harald
回答(1 个)
Harald
2024-3-8
Hi,
one way to do that sort of "manual fit" would be to use a slider or comparable interactive component in Live Editor.
For more details on this, please see https://www.mathworks.com/help/matlab/matlab_prog/add-interactive-controls-to-a-live-script.html
However, the intention may be that you write an own simple optimization algorithm to automatically find the best kn.
Best wishes,
Harald
7 个评论
Harald
2024-3-10
Even if the optimality measures look good, this might only be a local minimum, not the global minimum that you are looking for.
To use fminsearch, you need to use an anonymous function handle, see the example "Minimize with Extra Parameters" in the doc of fminsearch.
Again, please share sample data for further assistance.
Best wishes,
Harald
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!