Dear Jose,

Le mercredi 27 février 2013 14:18:45 UTC+1, Jose Guzman a écrit :
>
> I am trying to find the maximun of an exponential expression of the form: 
>
> sage: t=var('t') 
> sage: g(t) = e**(-t/10)-e^(-t/2) 
>
> between 0 and say 50. My idea is to get the maximun to normalize the 
> function to that maximum and obtain the algebraic. For that: 
>
> sage: diff(g,t)==0,t) 
>
> But sage returns: 
> [e^(1/2*t) == 5*e^(1/10)*t] 
>
> How can I restrict this value to the interval between 0 and 50? 
>

No need to. Here follows the text version of a Sage notebook worksheet 
explaining the solutions (and some problems with them). Copy that, create a 
new worksheet, go to "text mode", paste and revert to "worksheed mode", 
restart the workshet and re-evaluate.

----- Cut here -----

<p>Probl&egrave;m found in the sage-support list (<a 
href="https://groups.google.com/forum/#!topic/sage-support/OvlwzWksSyI";>https://groups.google.com/forum/#!topic/sage-support/OvlwzWksSyI</a>)
 : maximum of g(t)= $e^{-t/10}-e^{-t/2}$ "between 0 and (say) 50....</p>
<p>Let's setup :</p>
sage: var('y,x,y')
sage: g(t)=e^(-t/10)-e^(-t/2)
sage: dg=diff(g(t),t)
sage: print dg
1/2*e^(-1/2*t) - 1/10*e^(-1/10*t)
sage: plot(g(t), [t,0,50])
<html><font color='black'><img src='cell://sage0.png'></font></html>
<p>This graph supports the idea that g(t) has indeed a maximum around t=4.</p>
<p>Let's try to solve directly :</p>
sage: e0=solve(dg==0,t)
sage: print e0
[
e^(1/2*t) == 5*e^(1/10*t)
]
<p>This means that the defult solver does not find solutions, and returns a 
possibly more interestng form of the original equation.</p>
<p>Now, if we suppose $t\in\mathbb{R^{*+}}$, log(t) is an increasing bijection, 
therefore 
$\mathrm{a}(t)=\mathrm{b}(t)\Leftrightarrow\log(\mathrm{a}(t))=\log(\mathrm{b}(t))$.</p>
<p>Sage needs a little expression massage to make this useful, but gives a 
solution consonant to the graphical representation.</p>
sage: e1=e0[0]
sage: print log(e1.lhs()).simplify_log()
sage: print log(e1.rhs()).simplify_full()
sage: s1=solve(log(e1.lhs()).simplify_log()==log(e1.rhs()).simplify_full(), t)
sage: print "s1 : ", s1
sage: print "for t = ", s1[0].rhs().N(), "g(t) = ", g(s1[0].rhs().N()), " ; 
d(g(t))/dt = ", dg.subs({t:s1[0].rhs()}).simplify_full()
1/2*t
1/10*t + log(5)
s1 :  [
t == 5/2*log(5)
]
for t =  4.02359478108525 g(t) =  0.534992243981138  ; d(g(t))/dt =  0
<p>Since s1 is &nbsp;irst-degree equation in t, this is the only real 
nonnegative maximum (it is easy to show that there is no negative maximum).</p>
<p>Now, try brute force via the to_poly_solve solver :</p>
sage: s2=solve(dg==0, t, to_poly_solve=True)
sage: s2
[t == 10*I*pi + 20*I*pi*z87 + 5/2*log(5), t == -5*I*pi + 20*I*pi*z91 + 
5/2*log(5), t == 20*I*pi*z89 + 5/2*log(5), t == 5*I*pi + 20*I*pi*z93 + 
5/2*log(5)]
<p>But there is a problem : all these solutions are strictly complex (nonzero 
imaginary part). the to_poly_solve solver misses the only real root of e1... 
This is a Maxima bug.</p> 

<p>Additional note : when using to_poly_solve from Sage, the constraints on 
the z constants are not reimported in Sage (they are added to the Maxima's 
facts() database). Should this be flagged as a Sage bug ?</p> 

----- Cut here -----

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to