curve fit exactly the function I enter

2 Ansichten (letzte 30 Tage)
JuiChun Lin
JuiChun Lin am 11 Jun. 2018
Kommentiert: John D'Errico am 12 Jun. 2018
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 Kommentare
JuiChun Lin
JuiChun Lin am 11 Jun. 2018
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 am 11 Jun. 2018
Your data probably doesn't match the model very well. That happens a lot.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 11 Jun. 2018
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 Kommentare
Walter Roberson
Walter Roberson am 11 Jun. 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 am 12 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by