How can I model conditionally defined exponential functions?

2 visualizaciones (últimos 30 días)
Thomas Veith
Thomas Veith el 30 de Nov. de 2018
Comentada: Image Analyst el 30 de Nov. de 2018
I am using the MatLab Curve Fitting Toolbox to model a conditionally defined exponential function. My function is that y = exp(g) from 0 to 3, exp(p) from 3 to 4, and exp(g) from 4 to 7 (and I import g and p in an Excel spreadsheet). So it looks like the following:
function y=f(g,p)
t=(0:1:7)';
y1=exp(g).*(0<=t & t<=3);
y2=exp(p).*(3<t & t<=4);
y3=exp(g).*(4<t & t<=7);
y=y1+y2+y3;
end
And I build the model as follows:
v = fit(t,f(g,p),'exp2');
But that gives me a fitted curve that doesn't take account of the fact that that exp(g) is 'turned off' from 3 to 4, and so I get a big outlier as in the attached image. Any advice?
hyp1modelfailfailfail.jpg

Respuesta aceptada

TADA
TADA el 30 de Nov. de 2018
First of all, it's hard to get a good fit out of so little data points.
Second, your data in the code example is not a simple exponential function,
y = exp(g)*t
I think t is not a constant parameter, is it?
Moreover, I could be mistaken, but in the curve it looks like g and p are constants, because it's so straight, which means this is actually a linear function.
More importantly, the exponential fit works for a sum of exponentials, not a piecewise function of exponentials.
fit exponential model is that:
and not this:
for the later, I think you will have to map the discontinuities first (assuming you don't know their locations in advance) then fit seprately for each range
(Or if anyone knows how to do it with fit I will love to know too)
I know some people use fft or haar to find discontinuities, but if you know this is a decaying exponent, i think the simplest way is to use diff. the locations where the difference is positive, are the discontinuities. If this is an actual signal measured by some instrument and you have noise, you'll have to evaluate the noise and set some threshold to distinguish noise from discontinuities.

Más respuestas (0)

Categorías

Más información sobre Fit Postprocessing 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