fiitting data

Hello everyone:
My question is not only about matplotlib, but I wonder if I can do what I want with some matplotlib subroutine, instead of the one for scipy.
I’m new using scipy, so I’m sorry if any of my questions are silly.

I’m trying to find the maxima, absolut and local, of a function, in order to
fit an exponencial curve and get de exponecial argument.

My function if the soluction of a couple equations system:

···

def derivs3(x,t,gamma,omega,dl):
d1 = omegax[2] - gamma x[0]
d2 = dl
x[2] - (gamma/2.)
x[1]
d3 = -omega x[0] - dlx[1] - (gamma/2.)* x[2] + (omega/2.)
return d1,d2,d3

def solucion(a,t,gamma, omega, dl):
sol=odeint(derivs3,a,t,(gamma,omega,dl))
return sol

The case I’m interesting in, the soluction have the form of a sin*exp, so I

want to find the function that envolves it, a exponencial function.
To do this, I can find the maximas, and fit them, so I use:

def g4(t1):
sol2=odes.solucion((0.5
,0,0),t1,0.5,5,0)
return sol2[:,0]

x_max = optimize.fminbound(g4,0,2)

To use fminbound, I need a function that returns only a single array, so I use
de g4 function.

I use (0,2) as bounds.
The problem I have is that the return is:

x_max
1.9999959949686341


That aren’t the maximas in the interval.
If I change the interval:


x_max = optimize.fminbound(g4,0.1,4)

x_max
3.9999945129622403


And so on.
I don’t know what I’m doing wrong, so if everyone can help, I’m going to be really happy.

I wish if maybe there’s a better way to do it with matplotlib, but I don’t know.

Hello everyone:
My question is not only about matplotlib, but I wonder if I can do what I want with some matplotlib subroutine, instead of the one for scipy.
I’m new using scipy, so I’m sorry if any of my questions are silly.

I’m trying to find the maxima, absolut and local, of a function, in order to
fit an exponencial curve and get de exponecial argument.

My function if the soluction of a couple equations system:

coseno_amortiguado.png

···

def derivs3(x,t,gamma,omega,dl):
d1 = omegax[2] - gamma x[0]
d2 = dl
x[2] - (gamma/2.)
x[1]
d3 = -omega x[0] - dlx[1] - (gamma/2.)* x[2] + (omega/2.)
return d1,d2,d3

def solucion(a,t,gamma, omega, dl):
sol=odeint(derivs3,a,t,(gamma,omega,dl))
return sol

The case I’m interesting in, the soluction have the form of a sin*exp, so I

want to find the function that envolves it, a exponencial function.
To do this, I can find the maximas, and fit them, so I use:

def g4(t1):

 sol2=odes.solucion((0.5

,0,0),t1,0.5,5,0)
return sol2[:,0]

x_max = optimize.fminbound(g4,0,2)

To use fminbound, I need a function that returns only a single array, so I use
de g4 function.

I use (0,2) as bounds.
The problem I have is that the return is:

x_max
1.9999959949686341

That aren’t the maximas in the interval.
If I change the interval:


x_max = optimize.fminbound(g4,0.1,4)
x_max
3.9999945129622403

And so on.
I don’t know what I’m doing wrong, so if everyone can help, I’m going to be really happy.

I wish if maybe there’s a better way to do it with matplotlib, but I don’t know.

Hello everyone:
My question is not only about matplotlib, but I wonder if I can do what I want with some matplotlib subroutine, instead of the one for scipy.
I’m new using scipy, so I’m sorry if any of my questions are silly.

I’m trying to find the maxima, absolut and local, of a function, in order to
fit an exponencial curve and get de exponecial argument.

My function if the soluction of a couple equations system:

···

def derivs3(x,t,gamma,omega,dl):
d1 = omegax[2] - gamma x[0]
d2 = dl
x[2] - (gamma/2.)
x[1]
d3 = -omega x[0] - dlx[1] - (gamma/2.)* x[2] + (omega/2.)
return d1,d2,d3

def solucion(a,t,gamma, omega, dl):
sol=odeint(derivs3,a,t,(gamma,omega,dl))
return sol

The case I’m interesting in, the soluction have the form of a sin*exp, so I

want to find the function that envolves it, a exponencial function.
To do this, I can find the maximas, and fit them, so I use:

def g4(t1):

 sol2=odes.solucion((0.5

,0,0),t1,0.5,5,0)
return sol2[:,0]

x_max = optimize.fminbound(g4,0,2)

To use fminbound, I need a function that returns only a single array, so I use
de g4 function.

I use (0,2) as bounds.
The problem I have is that the return is:

x_max
1.9999959949686341


That aren’t the maximas in the interval.
If I change the interval:


x_max = optimize.fminbound(g4,0.1,4)

x_max
3.9999945129622403


And so on.
I don’t know what I’m doing wrong, so if everyone can help, I’m going to be really happy.

I wish if maybe there’s a better way to do it with matplotlib, but I don’t know.

scipy is your best bet -- matplotlib is a plotting library, with some
numerical stuff included for historical reasons. For robust, fast
data fitting, scipy is a better fit.

JDH

···

On 5/9/07, darkside <in.the.darkside@...287...> wrote:

Hello everyone:
My question is not only about matplotlib, but I wonder if I can do what I
want with some matplotlib subroutine, instead of the one for scipy.
I'm new using scipy, so I'm sorry if any of my questions are silly.

darkside wrote:

Hello everyone:
My question is not only about matplotlib, but I wonder if I can do what
I want with some matplotlib subroutine, instead of the one for scipy.
I'm new using scipy, so I'm sorry if any of my questions are silly.

I'm trying to find the maxima, absolut and local, of a function, in order to
fit an exponencial curve and get de exponecial argument.

My function if the soluction of a couple equations system:
------------
def derivs3(x,t,gamma,omega,dl):
        d1 = omega*x[2] - gamma *x[0]
        d2 = dl*x[2] - (gamma/2.)* x[1]
        d3 = -omega *x[0] - dl*x[1] - (gamma/2.)* x[2] + (omega/2.)
        return d1,d2,d3
def solucion(a,t,gamma, omega, dl):
        sol=odeint(derivs3,a,t,(gamma,omega,dl))
        return sol
--------------------------------------
The case I'm interesting in, the soluction have the form of a sin*exp, so I
want to find the function that envolves it, a exponencial function.
To do this, I can find the maximas, and fit them, so I use:

Why don't you fit the solution to sin*exp? You could estimate frequency/phase
via fft and use it as an initial guess.

Christian

ps: It's considered to be rude to post the same message three times within one
day. Btw. many people here read both scipy and matplotlib mailing lists.