ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 17 May 2013 00:55:36 -0500solve solution change after cell evaluationhttps://ask.sagemath.org/question/10127/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
Thanks in advanceThu, 16 May 2013 23:20:46 -0500https://ask.sagemath.org/question/10127/solve-solution-change-after-cell-evaluation/Answer by vdelecroix for <p>Hello everyone,</p>
<p>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</p>
<p>cell1</p>
<pre><code># 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)
</code></pre>
<p>cell2</p>
<pre><code># 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
</code></pre>
<p>cell3</p>
<pre><code>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)
</code></pre>
<p>The values for kf started at 0.49 and are wandering towards 0.35</p>
<p>Thanks in advance</p>
https://ask.sagemath.org/question/10127/solve-solution-change-after-cell-evaluation/?answer=12386#post-id-12386Your `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,2Thu, 16 May 2013 23:37:04 -0500https://ask.sagemath.org/question/10127/solve-solution-change-after-cell-evaluation/?answer=12386#post-id-12386Comment by vdelecroix for <p>Your <code>A</code> in the second cell depends on <code>k</code> which is computed in the third cell (as a fit parameter)... Then your <code>testmodel</code> is different at each execution of 3,2</p>
https://ask.sagemath.org/question/10127/solve-solution-change-after-cell-evaluation/?comment=17672#post-id-17672It is always hard to debug its own code ! I made much more stupid mistakes ;-)Fri, 17 May 2013 00:55:36 -0500https://ask.sagemath.org/question/10127/solve-solution-change-after-cell-evaluation/?comment=17672#post-id-17672Comment by god.one for <p>Your <code>A</code> in the second cell depends on <code>k</code> which is computed in the third cell (as a fit parameter)... Then your <code>testmodel</code> is different at each execution of 3,2</p>
https://ask.sagemath.org/question/10127/solve-solution-change-after-cell-evaluation/?comment=17673#post-id-17673I'm ashamed that my mistake is so trivial. Thank you for your fast answer.Fri, 17 May 2013 00:42:15 -0500https://ask.sagemath.org/question/10127/solve-solution-change-after-cell-evaluation/?comment=17673#post-id-17673