fit non-linear scatter

7 visualizaciones (últimos 30 días)
Marc Jakobi
Marc Jakobi el 9 de Nov. de 2013
Respondida: Marc Jakobi el 9 de Nov. de 2013
Hi
I have a bunch of scatters that I am trying to get a trend line for:
Plot = figure;
PV_KL = axes('Parent',Plot);
hold(PV_KL,'all');
scatter(U1, I1,'r','filled');
hold on
scatter(U2, I2,'b','filled');
U = linspace(0,1000,5000);
Poly1 = polyfit(U1,I1,5);
Poly2 = polyfit(U2,I2,5);
Trend1 = polyval(Poly1,U);
Trend2 = polyval(Poly2,U);
hold on
plot(U,Trend1,'k','LineWidth',1.5);
hold on
plot(U,Trend2,'k','LineWidth',1.5);
xlim([0 max(U1)+100]);
ylim([0 max(I1)+100]);
grid;
The polynomial order "5" in polyfit() gives me the best trend line so far, but the scatters actually represent measured logarithmic and exponential functions and not polynomials, so my trend lines are not quite right. Is there another function like polyfit() that I can use for logarithmic / exponential scatters? If so, how would you use it in my code?
Thanks in advance for any help!
I found the function
nlinfit()
which I suppose should work. But I am having trouble understanding how to use it (the fourth parameter). I am trying to get a fit for I over U according to the function
I = I_0 - exp(U/U_T)-1)
U is the variable on the x-axis and I on the y-axis.

Respuesta aceptada

Marc Jakobi
Marc Jakobi el 9 de Nov. de 2013
Nevermind. I figured it out.
Modelfun1 = @(beta1,xx)(beta1(1)-beta1(2).*(exp(xx./(beta1(4).*beta1(3)))-1));
Modelfun2 = @(beta2,xx)(beta2(1)-beta2(2).*(exp(xx./(beta2(4).*beta2(3)))-1));
beta1 = [I1(1) 1E-6 26 0.8];
beta2 = [I2(1) 1E-6 26 0.92];
Poly1 = nlinfit(U1,I1,Modelfun2,beta1);
Poly2 = nlinfit(U2,I2,Modelfun2,beta2);
Poly3 = polyfit(U1,P1,4); Poly4 = polyfit(U2,P2,4);
Trend1 = Modelfun1(Poly1,U); Trend2 = Modelfun2(Poly2,U);
Trend3 = polyval(Poly3,U); Trend4 = polyval(Poly4,U);
hold on
plot(U,Trend1,'k','LineWidth',1.5);
hold on
plot(U,Trend2,'k','LineWidth',1.5);
hold on
...
I had to design the function in Modelfun and estimate the coefficiants in beta.

Más respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by