Ask Your Question
1

solve solution change after cell evaluation

asked 2013-05-16 23:20:46 -0600

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-16 23:37:04 -0600

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 00:42:15 -0600 )edit
1

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

vdelecroix gravatar imagevdelecroix ( 2013-05-17 00:55:36 -0600 )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-16 23:20:46 -0600

Seen: 46 times

Last updated: May 16 '13