curve fit exactly the function I enter

I have some data points and a known function with 4 parameters. But when I tried to use the 'cftool', part of the data points aren't fitting the curve. The function is 2 exponential terms but I enter it as customized function.

3 comentarios

John D'Errico
John D'Errico el 11 de Jun. de 2018
Editada: John D'Errico el 11 de Jun. de 2018
Just because you picked a function does not mean that it can be used to fit any set of points.
Perhaps you are trying to imply that the points are generated by evaluating them form a known function, and you are tying to test fit the function, to see if the curve fit "works"?
What you need to understand is that you need to supply adequate starting values, that sums of exponentials are difficult things to fit, and that no optimization is guaranteed to converge to the solution that you want to see.
So, if it failed to converge to the solution you wanted, then provide adequate starting values.
Hello John, I understand but what I'm trying to do is to take experimental data ( over 200 points ) to fit into a function (known) that contains 4 variables. The code is follow:
clear,clc
load hahn1 %curve fitting preload
%cftool %this can be used as interactive tool to curve fitting with
%customized equation but I still haven't figured out how to correctly enter
%the equation
F=96485; %faraday's constant
R=8.314; %gas constant;
T=298; %temperature
A = xlsread('Polarization Curve modeling_new.xlsx','A4:A104'); %read the excel file at system's directory
B = xlsread('Polarization Curve modeling_new.xlsx','J4:J104'); %''
B1=log(abs(B)); %log scale of the current
C=fit(B,A,'exp2') %fit B and A from the excel using 2 exponential terms
subplot(2,1,1) %set plot location
plot(C,B,A) %plot
xlabel('Potential')
ylabel('Current')
title('Total')
From the graph, we can see that the function isn't overlaying some parts after the bent. The function is
y=a*exp(b*x)+c*exp(d*x)
where I need to optimize a,b,c and d to fit all points from the data provided.
Walter Roberson
Walter Roberson el 11 de Jun. de 2018
Your data probably doesn't match the model very well. That happens a lot.

Iniciar sesión para comentar.

 Respuesta aceptada

John D'Errico
John D'Errico el 11 de Jun. de 2018

0 votos

So why do you think that a sum of two exponentials MUST fit this data? Looking at the data, that hardly seems a good conclusion.
However, if also seems that it is still very probable that the curve fitting process has not converged to a viable solution, because of several reasons.
1. The starting values used were poor. This is almost always the case for exponential models, and especially sums of exponentials. They are already problem children of the curve fitting world. So first, you MAY need to learn how to provide intelligent starting values to the curve fitting toolbox. That may well mean you need to learn how to gain a good set of starting values.
2. The curve that you show is a classically poor one for curve fitting, because much of the data lies on a vertical line. That means that regression techniques will tend to fail miserably, UNLESS you can provide incredibly better starting values than the random ones that fit will use.
3. The curve that you show is NOT one that looks terribly like the sum of two exponentials. That is to say, it exhibits significant lack of fit. So I will seriously question why it is that you think this is a good choice of model.
4. I note that you have created the variable B1 using a log transform, but then never use it.
Option # 3 above is, I feel, the most telling here. AN exponential model will show a smoothly rising shape. But an exponential model will not have a curve shape that is asymptotic to a straight line, as you seem to have here.
So the lack of fit that you see here is symptomatic, indicating that you have very possibly chosen the wrong model form. Or it may simply be an artifact of the plot that you used, because you created B1, but never actually use that variable.
Just wanting a specific model to fit any set of data is not sufficient. You need to make an intelligent choice of model. One way that I can help here is if you provide the data itself, as an attachment. Just use the paper clip to attach a .mat file that has the data in it. Then I might be able to make some suggestions as to a better choice of model, or how to choose better starting values. That may involve a good choice of how to better transform your data, BEFORE the curve fit.
So if you seriously want help, then you need to provide the data. As I said, just save A and B into a single .mat file. Then attach it to a comment, or to your original question.

4 comentarios

Walter Roberson
Walter Roberson el 11 de Jun. de 2018
Note: you can zip your xlsx and attach the zip
John D'Errico
John D'Errico el 11 de Jun. de 2018
Editada: John D'Errico el 11 de Jun. de 2018
I suggested a .mat file, because often people have other data in an xlsx file they may feel is sensitive. But the original file is arguably better than a .mat file, in case that may prove useful to understand where the data came from.
Any way the data is provided is a useful thing, allowing us to help solve the problem. Otherwise, we can only make guesses as to a possible solution. I have a few conjectures that I MIGHT make, but they would only be vague conjectures.
Walter Roberson
Walter Roberson el 11 de Jun. de 2018
If you attach your data, I will run it through a private global minimizer tool I have been working on, to find the best fit.
John D'Errico
John D'Errico el 12 de Jun. de 2018
Still waiting to see your data. You don't truly need a global minimizer for this problem. However, there are good algorithms and ones that are more sensitive to starting values. So until we see some data, we are unable to provide good help for you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Jun. de 2018

Comentada:

el 12 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by