Ask Your Question
1

solve solution change after cell evaluation

asked 2013-05-17 06:20:46 +0100

god.one gravatar image

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

Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-05-17 06:37:04 +0100

vdelecroix gravatar image

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

edit flag offensive delete link more

Comments

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

god.one gravatar imagegod.one ( 2013-05-17 07:42:15 +0100 )edit
1

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

vdelecroix gravatar imagevdelecroix ( 2013-05-17 07:55:36 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-17 06:20:46 +0100

Seen: 250 times

Last updated: May 17 '13