# solve solution change after cell evaluation Hello everyone,

I wanted to fit some data and I found a strange behaviour of solve(). After evaluating cell 1,2 and 3 and further evaluations of cell 2,3,2,3,2,3,... the solution for kf changes and gets smaller and smaller. I use Sage 5.9 in a VM in Win7Prof

cell1

# data=[another list]
data=((0.004,34.915),(0.018,34.665),(0.040,34.254),(0.071,33.695),(0.159,32.146),(0.282,30.323))
p1=list_plot(data,plotjoined=True,xmin=0,xmax=1,ymin=20,ymax=35)


cell2

# modell for fitting
lg=20
lm=35
A=(lm-lg)/(1-exp(-k))
c=lm-A
var('kf')
testmodel(t)=c+A*exp(-kf*t)

best_fit_par=find_fit(data,testmodel(t),initial_guess=[0.5],parameter=[kf],variables=[t],solution_dict=True)
print 'best_fit_par'
print best_fit_par


cell3

k=best_fit_par[kf]
lg=20
lm=35
A=(lm-lg)/(1-exp(-k))
c=lm-A
p2=plot(A*exp(-k*t)+c,(t,0,1),xmin=0,xmax=1,ymin=20,ymax=35)
show(p1*p2)


The values for kf started at 0.49 and are wandering towards 0.35

edit retag close merge delete

Sort by » oldest newest most voted

Your A in the second cell depends on k which is computed in the third cell (as a fit parameter)... Then your testmodel is different at each execution of 3,2

more

I'm ashamed that my mistake is so trivial. Thank you for your fast answer.

1

It is always hard to debug its own code ! I made much more stupid mistakes ;-)