Azzera filtri
Azzera filtri

select the x0 (initial point for x ) in the curve fitting with lsqcurvefit

3 visualizzazioni (ultimi 30 giorni)
I wanted to fit an arbitrary function ( (k_plus-k_t*(1-exp(-k_plus/(a*k_t+b*k_d)))-k_d*(exp(-k_plus/(a*k_t+b*k_d)) to my data set. Therefore, I used lsqcurvefit in MATLAB. The code was as follow:
clc;
clear all;
close all;
k_plus =[0.1 0.2 0.4 0.7 1 1.1 1.2 1.5 1.7 2 2.5 3 3.5 4 5];
K_minus_d = [0.1 0.2 0.4 0.7 1 1.1 1.2 1.5 1.7 2 2.5 3 3.5 4 5];
K_minus_t =[ 0.1 0.2 0.4 0.7 1 1.1 1.2 1.5 1.7 2 2.5 3 3.5 4 5];
f1= sprintf('table%02d.txt',1);
data=tblread(f1);
x1=data(:,1);
x1=x1';
F=@(c,xdata)(xdata-K_minus_t*(1-exp(-xdata/(c(1)*K_minus_t+c(2)* K_minus_d)))- K_minus_d*(exp(-xdata/(c(1)*K_minus_t+c(2)* K_minus_d)))
x0 = [0.1 0.1];
[c,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,k_plus,x1)
figure;
hold on
plot(k_plus,x1,'r-', 'LineWidth', 1)
plot(k_plus,F(c,k_plus),'-b*','LineWidth', 1,'MarkerSize', 1)
hold off
grid on;
I wonder how can I select the x0 (initial point for x) because I got different value for C when I change it
  3 Commenti
Matt J
Matt J il 10 Set 2014
Modificato: Matt J il 10 Set 2014
Since the denominator in
xdata/(c(1)*K_minus_t+c(2)* K_minus_d)
is a vector, it seems likely that you should you be doing element-wise division instead,
xdata./(c(1)*K_minus_t+c(2)* K_minus_d);
Do you understand the difference?

Accedi per commentare.

Risposte (1)

John D'Errico
John D'Errico il 10 Set 2014
There is no magic way to choose the right starting values. If there were, then the optimizer would use it in the first place. Even better, if there were a great way to find the perfect starting values, then why need an optimizer to solve the problem?
As you have seen, starting from a different point means you will sometimes get different solutions, not always the best one either. So you need to start with a good set of starting values! And if you know anything about the function you are fitting, there is a good chance that YOU are the best person to choose the right start value so the solver won't need to work so hard. Don't just get lucky, get good.
If you are absolutely hopeless here, and cannot choose a good set of starting values, then use multiple sets for the solver, generated randomly. Start it from each point, then select the solution that is best. (My tool on the File Exchange, RMSEARCH, helps you with the mechanics of choosing multiple points, then starting an optimizer of your choice with each point, and then returning the solutions it found ordered in sequence from good to bad.)
  1 Commento
Matt J
Matt J il 10 Set 2014
Modificato: Matt J il 10 Set 2014
@Ahmed,
In addition to what John said, your model function F is over-parametrized. It depends on unknown parameters c(1) and c(2) entirely through the expression
c(1)*K_minus_t+c(2)* K_minus_d
Since K_minus_t and K_minus_d are the same vector, there are infinite combinations of c(1) and c(2) that produce any given value for the above expression. So, no wonder you are seeing non-uniqueness in the solution.

Accedi per commentare.

Categorie

Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by