ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 05 Mar 2020 21:38:23 +0100How to tell to sagemath to solve for the good roothttps://ask.sagemath.org/question/50160/how-to-tell-to-sagemath-to-solve-for-the-good-root/ Hello, this is a simple problem of optimization
> %display latex
>
> var('w, gamma, alpha, beta, h, theta,
> p, A, B'); U= w^(gamma); Pi =
> p*h^(theta)- w*h; N= (U)^alpha *
> (Pi-B)^beta show(U) show(Pi) show(N)
> show(N_w)
> N_w= factor(N.diff(w))
> assume(0 < alpha <1)
> assume(0 < beta <1)
>z=solve(N_w==0, w, solution_dict=True)
>show(z)
If I say no bulshit, with the assumptions only one solution is valid. But Sagemath display all solutions ? How could it be done automaticaly ?
The factoriZation shows that
> assume(0 < alpha <1) assume(0 < beta
> <1) z=solve(N_w==0, w,
> solution_dict=True)Wed, 04 Mar 2020 13:21:18 +0100https://ask.sagemath.org/question/50160/how-to-tell-to-sagemath-to-solve-for-the-good-root/Comment by dsejas for <p>Hello, this is a simple problem of optimization</p>
<blockquote>
<p>%display latex</p>
<p>var('w, gamma, alpha, beta, h, theta,
p, A, B'); U= w^(gamma); Pi =
p<em>h^(theta)- w</em>h; N= (U)^alpha *
(Pi-B)^beta show(U) show(Pi) show(N)
show(N_w)
N_w= factor(N.diff(w))
assume(0 < alpha <1)
assume(0 < beta <1)
z=solve(N_w==0, w, solution_dict=True)
show(z)</p>
</blockquote>
<p>If I say no bulshit, with the assumptions only one solution is valid. But Sagemath display all solutions ? How could it be done automaticaly ?</p>
<p>The factoriZation shows that </p>
<blockquote>
<p>assume(0 < alpha <1) assume(0 < beta
<1) z=solve(N_w==0, w,
solution_dict=True)</p>
</blockquote>
https://ask.sagemath.org/question/50160/how-to-tell-to-sagemath-to-solve-for-the-good-root/?comment=50177#post-id-50177I am afraid Sage is not clever (heuristic) enough to automatically choose the correct solution. A human should do it manually. If this is for students to do it, it should be a good exercise for them. If this is to automatically fill the solution on a book or article you are writing, you could write a small piece of code that makes the correct selection. However, remember, it is only guaranteed to work for this particular problem, and could fail to work if you change the assumptions or the equation itself, or if you add another equation.
Anyway, I am only posting this as a comment because it is not an answer to your question, and also it could be that somebody more clever and Sage-savvy than me actually finds a solution to your problem. I hope so!Thu, 05 Mar 2020 21:38:23 +0100https://ask.sagemath.org/question/50160/how-to-tell-to-sagemath-to-solve-for-the-good-root/?comment=50177#post-id-50177Comment by dsejas for <p>Hello, this is a simple problem of optimization</p>
<blockquote>
<p>%display latex</p>
<p>var('w, gamma, alpha, beta, h, theta,
p, A, B'); U= w^(gamma); Pi =
p<em>h^(theta)- w</em>h; N= (U)^alpha *
(Pi-B)^beta show(U) show(Pi) show(N)
show(N_w)
N_w= factor(N.diff(w))
assume(0 < alpha <1)
assume(0 < beta <1)
z=solve(N_w==0, w, solution_dict=True)
show(z)</p>
</blockquote>
<p>If I say no bulshit, with the assumptions only one solution is valid. But Sagemath display all solutions ? How could it be done automaticaly ?</p>
<p>The factoriZation shows that </p>
<blockquote>
<p>assume(0 < alpha <1) assume(0 < beta
<1) z=solve(N_w==0, w,
solution_dict=True)</p>
</blockquote>
https://ask.sagemath.org/question/50160/how-to-tell-to-sagemath-to-solve-for-the-good-root/?comment=50162#post-id-50162Hello, @Cyrille! I have some bad news: The `assume` statements can only be enforced when the solution is numerical. For example,
assume(x>0)
solve(x^2==4)
will return `[x==2]`, ignoring the alternative solution $x=-2$, which doesn't satisfy the assumption. On the other hand, observe this example, which is should have no solution:
var('b')
assume(x, 'real')
assume(b<0)
solve(x^2==b,x)
but Sage returns `[x == -sqrt(b), x == sqrt(b)]`, which obviously violate the assumptions.
At first, I thought I had a form to avoid this problem (I even posted it as a comment); however, every time I test it, there is always a particular case that makes it fail. I even tried other approaches, but they also failed on a particular case.Wed, 04 Mar 2020 17:08:34 +0100https://ask.sagemath.org/question/50160/how-to-tell-to-sagemath-to-solve-for-the-good-root/?comment=50162#post-id-50162