Is there a way to fit experimental data to a set of x,y points?

4 Ansichten (letzte 30 Tage)
I have obtained experimental data and would like to fit it to a first order Hankel function. I have the specific Hankel function as a set of [x,y] points in a csv file and would like to fit my experimental data to this plot. Is there a way to do this in Matlab? I'm familar with matlab curve fitting, but im not sure how to fit data to x,y points.

Akzeptierte Antwort

Star Strider
Star Strider am 21 Jul. 2023
Bearbeitet: Star Strider am 22 Jul. 2023
Hankel functions are new to me, so I looked this up. Wolfram MathWorld a has a description:
where is besselj and is bessely in MATLAB.
I suppose that you could fit those using the first argument ν as the parameter to be estimated, with z being the independent variable.
That objective function would be something like this:
H1fcn = @(nu,z) besselj(nu,z) + 1i*bessely(nu,z);
although I have my rervations as to how it would work, given the imaginary operator. It might be necessary to enclose it within the abs function. I leave those details to you.
EDIT — (22 Jul 2023 at 17:02)
Corrected typographical errors, attempted data reconstruction and nonlinear fit —
x = linspace(1E-4, 0.25, 100).'; % Create Data
y = 650*exp(-150*x); % Create Data
H1fcn = @(nu,z) besselj(nu,z) + 1i*bessely(nu,z); % First-Order Hankel Function
mdl = fitnlm(x,y,@(nu,z)abs(H1fcn(nu,z)), 1) % Fit Function To Data
mdl =
Nonlinear regression model: y ~ F(nu,z) Estimated Coefficients: Estimate SE tStat pValue ________ _________ ______ __________ b1 0.75324 0.0088237 85.366 1.5941e-94 Number of observations: 100, Error degrees of freedom: 99 Root Mean Squared Error: 52.7 R-Squared: 0.624, Adjusted R-Squared 0.624 F-statistic vs. zero model: 179, p-value = 6.33e-24
B = mdl.Coefficients.Estimate;
figure
plot(x, y, '.', 'DisplayName','Data (Synthetic)')
hold on
plot(x, abs(H1fcn(B,x)), 'DisplayName','Function Fit')
hold off
grid
xlabel('X')
ylabel('Y')
title('First-Order Hankel Function: Fit to Simulated Data')
legend('Location','best')
You might be able to get a better fit with the actual data.
.
  2 Kommentare
Todd Fayard
Todd Fayard am 24 Jul. 2023
Thank you very much, I think I will have to build a custom fit based on this setup. This is very helpful!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

the cyclist
the cyclist am 20 Jul. 2023
If you have the Statistics and Machine Learning Toolbox, you should be able to do this type of fit with fitnlm (or possibly fitlm).
If you want more detailed help, please post your data (using the paper clip icon in the INSERT section of the toolbar), and the form of the equation you are trying to fit.
  2 Kommentare
the cyclist
the cyclist am 20 Jul. 2023
Immediately after I posted this answer, I realized that I don't really understand what "I have the specific Hankel function as a set of [x,y] points in a csv file" means. The (x,y) points and the experimental are two different things?
Todd Fayard
Todd Fayard am 20 Jul. 2023
Hi, yes... the i would like to fit my experimental data to a set of [x,y] points. Thank you for the response.

Melden Sie sich an, um zu kommentieren.


the cyclist
the cyclist am 22 Jul. 2023
Informed by your comments on my other answer, I have a different one. Unfortunately, that answer is "What you are asking to do is not sensible". This forum is not the easiest way to explain why, but I'll try. We need to step through a few concepts.
First, note how you say you want to "fit my experimental data to this plot". This is backward. You do not fit experimental data to something. You fit something (usually a function) to the data. This may seem like nit-picky English, but it is crucial to the reason why your question is not sensible.
Second, think about what it specifically means to fit a function to experimental data. Let's take the easy case of fitting a straight line to data. What does it mean to "fit"? In the case of fitting a line to data, it means finding the values of the two free parameters of the line (the intercept and slope) that give the minimum error between the line and the data. The fitting process is the finding of the best parameters. (This would also be true if you were fitting a more complex function.)
Finally, considering your question, of "fitting" a fixed set of points to a fixed set of experimental data. You have a problem. There are no free parameters. You cannot fit the (x,y) points to the data, because there is nothing to tune.
Perhaps there is something I am misunderstanding, or perhaps there is some important aspect of your problem that you have not told us here. But as stated, the problem is not solvable.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by