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.Sat, 04 Mar 2023 13:36:26 +0100Applying a bivariate function to a list of coupleshttps://ask.sagemath.org/question/66773/applying-a-bivariate-function-to-a-list-of-couples/I have this function :
def F(v,a):
if v > a :
return 4*a - 3*(v-a)
else :
return v - 2*(a-v)^2
I want to applied it to `L2` define by
L0=list(range(4))
L1=list(range(4))
L2=flatten([[(v,a) for v in L0] for a in L1],max_level=1)
The only way I found to do this is the following
Vv=[(x,F(x[0],x[1])) for x in L2]
Vv
I wonder if there is a more efficient, elegant way to do this like with `apply_map()`.CyrilleSat, 04 Mar 2023 13:36:26 +0100https://ask.sagemath.org/question/66773/On mutating a variable to a functionhttps://ask.sagemath.org/question/66643/on-mutating-a-variable-to-a-function/In looking to the page `https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/tests.html` by accident, I have discovered an incredible feature of Sagemath : the fact that a variable can be transformed in a function and vis-versa. It is very nice for an economist (not only but it is what I am) in the following code
var('x y p_x p_y R λ')
U(x,y)= x*y
L(x,y,λ)= U(x,y)+λ*(R-p_x*x-p_y*y)
sol = solve([L(x,y,λ).diff(x)==0,L(x,y,λ).diff(y)==0,L(x,y,λ).diff(λ)==0], (x,y,λ))
show(sol[0][0])
x = function('x')
x = sol[0][0].rhs()
show(LatexExpr(r'\frac{dx}{dR} = '),x.diff(R).simplify())
My question : is there a shorten way to have access to `x` than writting `x = sol[0][0].rhs()` since `show(sol[0][0])` display the relation correctly (but without `x = sol[0][0].rhs()`, I can't obtain the desired result).
**Incidently, I think that this incredible feature is not enough publicized.**CyrilleFri, 24 Feb 2023 10:24:27 +0100https://ask.sagemath.org/question/66643/Displaying a smaller number of 0 for a Real callhttps://ask.sagemath.org/question/66631/displaying-a-smaller-number-of-0-for-a-real-call/ Suppose I define the function
var('A y')
f(A,x,y)= A*x^.25*y^.25
If I call `f(A,x,y)`, Sagemath returns `A*x^.250000000000000*y^.250000000000000`. I suppose that is the approximation of reals by defaults. But I would like to know if I can shorten the number of 0. CyrilleThu, 23 Feb 2023 16:39:42 +0100https://ask.sagemath.org/question/66631/Applying a polynomial to a matrixhttps://ask.sagemath.org/question/66042/applying-a-polynomial-to-a-matrix/ In the quickref for linear algebra, it is writen that, if `f(x) = x^2 + 5*x+3` then `f(B)` is possible.
I have tried
B=matrix([[1/2,2/3],[1/2,1/3]])
f(B)
but it returns an error when `B^2 + 5*B + 3` returns
[34 31 33 27]
[31 34 32 28]
[27 25 43 30]
[32 32 31 30]
I'm wondering?CyrilleSun, 22 Jan 2023 21:55:06 +0100https://ask.sagemath.org/question/66042/defining a functionhttps://ask.sagemath.org/question/65976/defining-a-function/if I define
f = e^(-x-y)
then
var('a,b')
f(a,b)
returns `e^(-a-b)`
f(1,1)
returns `e^(-2)`
But I want the real value. So here is my question, how to define a function (with the SageMath protocol or the `def` of Python such that if the arguments are variables it return the symbolic function with the symbolic variables and if the arguments are, say, explicit real value numbers? There is one more problem when the argument are of the type `(1,a)`.
There is a begining of answer in the asksagemath question "How to define Sage function with Optional arguments?" but in that case I do not know how to condition on say real or symbolic arguments.CyrilleWed, 18 Jan 2023 12:33:59 +0100https://ask.sagemath.org/question/65976/Max return a partial false resulthttps://ask.sagemath.org/question/64963/max-return-a-partial-false-result/ Suppose I have four (may be more) linear functions say :
f0(x) = -3 x
f1(x) = -3 x + 1
f2(x) = -6 x + 2
f3(x) = -9 x + 3
for $x \in [0, 1]$. They are easy to plot
plot((f0(x),f1(x),f2(x),f3(x)),(x,0,1),color=['red','blue','green','cyan'])
So one can see that for $x \in [0,1/3[$ $\max\{f0(x),f1(x),f2(x),f3(x)\} = f3(x)$ and for $x \in ]1/3, 1]$, $\max\{f0(x),f1(x),f2(x),f3(x)\} = f1(x)$.
But
max(f0(x),f1(x),f2(x),f3(x))
return only $f1(x)$. How to correct this result ?
CyrilleMon, 21 Nov 2022 08:01:19 +0100https://ask.sagemath.org/question/64963/Unable to calculate market equilibriumhttps://ask.sagemath.org/question/60184/unable-to-calculate-market-equilibrium/ Here is a huge notebook, but as the error arrives just at the end I am obliged to show that if Sage lacks of an `assume()` about a variable, I can't see which hypothesis is missing. The object of the notebook is to calculate the equilibrium price.
We begin by the demand side
var('a x y p_x p_y D Rev R l')
assume(a,'real')
assume(x,'real')
assume(y,'real')
assume(p_x,'real')
assume(p_y,'real')
assume(D,'real')
assume(Rev,'real')
assume(R,'real')
assume(l,'real')
assume(p_x,'real')
assume(p_y,'real')
assume(l,'real')
assume(l>0)
#assume(a>-1)
assume(a>0)
assume(p_x>0)
assume(p_y>0)
assume(R>0)
U =(1/(1-(1/a)))*x^(1-(1/a))+y
show(LatexExpr(r"""\text{La fonction d'utilité est }U(x,y) = """),U)
D= x*p_x + y*p_y
show(LatexExpr(r'\text{La Dépense } D = '),D)
Rev= R
show(LatexExpr(r'\text{Le Revenu } Rev = '),R)
L=U+l*(Rev-D)
show(LatexExpr(r'\text{Le lagrangien est } \mathcal{L}(x, y, λ) = '),L)
FOC = [diff(L,x),diff(L,y),diff(L,l)]
show(LatexExpr(r'\text{Les condition du premier ordre sont } \left\{\begin{array}{c}\mathcal{L}_x= 0\\\mathcal{L}_y= 0\\\mathcal{L}_λ= 0\end{array}\right. '))
show(LatexExpr(r'\text{soit }'))
show(LatexExpr(r'\mathcal{L}_x= 0 \Longleftrightarrow '),FOC[0]==0)
show(LatexExpr(r'\mathcal{L}_y= 0 \Longleftrightarrow '),FOC[1]==0)
show(LatexExpr(r'\mathcal{L}_λ= 0 \Longleftrightarrow '),FOC[2]==0)
sol = solve([FOC[0]==0,FOC[1]==0,FOC[2]==0],x,y,l, algorithm="sympy")
xs=sol[0][x]
ys=sol[0][y]
ls=sol[0][l]
show(LatexExpr(r"""\text{À l'optimum, on a :}"""))
show(LatexExpr(r' \,\,\,\,\,\,\,\,\, x^d = '),xs)
show(LatexExpr(r' \,\,\,\,\,\,\,\,\, y^d = '),ys)
show(LatexExpr(r' \,\,\,\,\,\,\,\,\, \lambda^\star = '),ls)
show(LatexExpr(r'\text{Si le bien } y \text{ sert de numéraire, on a : }p_y =1 \text{ et, ainsi :}'))
xsn=xs.substitute(p_y=1).factor()
ysn=ys.substitute(p_y=1).factor()
lsn=ls.substitute(p_y=1).factor()
show(LatexExpr(r' \,\,\,\,\,\,\,\,\, x^\star = '),xsn)
show(LatexExpr(r' \,\,\,\,\,\,\,\,\, y^\star = '),ysn)
show(LatexExpr(r' \,\,\,\,\,\,\,\,\, \lambda^\star = '),lsn)
show(LatexExpr(r'\text{On a :}'))
x_p=diff(xsn,p_x).simplify()
show(LatexExpr(r'x_p = '),x_p,LatexExpr(r'< 0.'))
Then follows the offer side
var('C c')
assume(c, 'real')
assume(c>0)
C= (1/2)*c*x^2
show(LatexExpr(r'\text{On suppose que la fonction de coût du producteur est : } C(x) ='), C)
pi=(p_x *x- C)
show(LatexExpr(r'\text{ Le profit est : } \pi(x) = '), pi)
pip= diff(pi,x)
show(LatexExpr(r'\text{ Le profit marginal est : } \pi^\prime(x) = '), pip, LatexExpr(r'( = 0\text{ à l}^\prime\text{optimum})'))
pipp= diff(pi,x,2)
show(LatexExpr(r"""\text{Il s'agit bien d'un maximum puisque : } \pi^{\prime\prime}(x) = """),pipp,LatexExpr(r'<0'))
prod=solve(pip==0,x)[0].rhs()
show(LatexExpr(r"""\text{L'offre de produit est : } x^o = """),prod)
And now the market equilibrium where Sage seems to lack an hypothesis :
show(LatexExpr(r'\text{L}^\prime\text{équilibre de concurrence pure et parfaite est caractérisé par le système d}^\prime\text{équations : } '))
show(LatexExpr(r'x^d = x^o'))
show(LatexExpr(r'x^d = '),xsn)
show(LatexExpr(r'x^o = '),prod)
pem= solve(xsn==prod, p_x)[0].rhs()
show(pem)
Also I would like to have the inverse demand fonction directly that is from the notebook if
$x_s= (1/p_x)^a \Longrightarrow p_x = (1/x_s)^{1/a}$, I have tried
def symbolic_inverse(f, x):
y = SR.var('y')
g = (f - y).roots(x, multiplicities=False)
return [expr.subs(y=x) for expr in g]
symbolic_inverse(SR(1/(x^(1/a))),x)
but even there it seem to lack an assumption.CyrilleThu, 09 Dec 2021 23:13:17 +0100https://ask.sagemath.org/question/60184/Solve return an implicit equationhttps://ask.sagemath.org/question/60119/solve-return-an-implicit-equation/The following `solve()` resists to any argument (to_poly_solve... calling giac sympy or anything else) in the way that it return an implicit solution in `y`
var('y')
A=n((1/2)*((1/4)*log(35000*0.25+100)+(3/4)*log(100)))
B=n((1/2)*((1/2)*log(35000*0.25+100)+(1/2)*log(100)))
C=(1/2)*A+ (1/2)*B
D=(1/2)*((1/2)*log(35000*0.25+100-y)+(1/2)*log(100-y))
sol=solve(D-C==0,y)[0]
sol
Of course I can find the solution acting the following way, but I find it after a long search and it seems inelegant.
sol1=e^sol.rhs()-e^sol.lhs()
sol21=n(solve(sol1==0,y)[0].rhs())
sol22=n(solve(sol1==0,y)[1].rhs())
show(sol21)
show(sol22)
Is there an other way ?CyrillePMon, 06 Dec 2021 18:13:58 +0100https://ask.sagemath.org/question/60119/Solve in real parametershttps://ask.sagemath.org/question/58753/solve-in-real-parameters/ I have a simple `solve()` line
var('x y')
solve(.25*x + 1.75*y, y)
Sagemath gives the good result but with rational parameters. Is there a pararameter which can keep the reals ?CyrilleMon, 30 Aug 2021 09:23:43 +0200https://ask.sagemath.org/question/58753/Inequation solution doesn't isolate the operational variablehttps://ask.sagemath.org/question/57364/inequation-solution-doesnt-isolate-the-operational-variable/This is a follow-up to
- [Ask Sage question 57318: Use solve with inequality extracted from polytope](https://ask.sagemath.org/question/57318)
- [Ask Sage question 57359: Symbolic expression not scriptable in Solve](https://ask.sagemath.org/question/57359)
One more time I encounter a problem I cannot find a solution by myself.
In the following code:
D = polytopes.dodecahedron()
DH = D.Hrepresentation()
x = list(var('x_%i' % i) for i in (0..2))
# show(DH)
Ineq=[[el.A()*vector(x) >= -el.b()] for el in DH]
# show(Ineq)
sol = [solve(ieq[0], x[0]) for ieq in Ineq]
sol1 = [el[1] for el in sol]
show(sol1)
when `ieq[0]` doesn't depend on `x[0]`, `sol1` is returned as entered.
It's perfectly normal. But I ask to solve on `x[0]`. Many answers do not
isolate `x[0]` (for instance, it is the case for `sol[2]`) which is what
I ask for. How can I code in such way that SageMath does it by default?CyrilleSun, 30 May 2021 16:25:44 +0200https://ask.sagemath.org/question/57364/Symbolic expression not scriptable in Solvehttps://ask.sagemath.org/question/57359/symbolic-expression-not-scriptable-in-solve/This is a follow-up to
- [Ask Sage question 57318: Use solve with inequality extracted from polytope](https://ask.sagemath.org/question/57318)
The answer by @slelievre to that question works nicely,
but I need to use indexed variables.
This variation of the code does not work for me:
D = polytopes.dodecahedron()
DH = D.Hrepresentation()
X = list(SR.var('x_%i' % i) for i in (0..2))
Ineq = [[el.A()*vector(X) >=el.b()] for el in DH]
show(Ineq[0][0])
sol = [solve(Ineq[i][0], x[1]) for i in range(len(Ineq))]
raising an error saying
'sage.symbolic.expression.Expression' object is not subscriptable
Why? the problem doesn't seem to come from `Ineq[0][0]` but from the variables?CyrilleSun, 30 May 2021 10:32:33 +0200https://ask.sagemath.org/question/57359/Use solve with inequality extracted from polytopehttps://ask.sagemath.org/question/57318/use-solve-with-inequality-extracted-from-polytope/Starting from a polytope, I would like to extract the inequalities
of its hyperplane representation and solve them with Sage's `solve`.
Define the dodecahedron and obtain its hyperplane representation.
sage: D = polytopes.dodecahedron()
sage: DH = D.Hrepresentation()
Pick the first inequality:
sage: DH[0]
An inequality (0, -1/2, -1/4*sqrt5 - 1/4) x + 1 >= 0
Try to feed it to `solve`:
sage: sol = solve(DH[0], x[1])
This doesn't work. So what can I do?CyrilleFri, 28 May 2021 10:32:38 +0200https://ask.sagemath.org/question/57318/Extending piecwise to 2 variables (or a variable and a parameter)https://ask.sagemath.org/question/54836/extending-piecwise-to-2-variables-or-a-variable-and-a-parameter/This piecewise function work correctly
score = piecewise([([i,i], ncand - i) for i in range(ncand)])
because `ncand` is defined earlier in my notebook. when I typeset say `score(1)` It returns what I expect. But I would like that ncand be a variable.CyrilleTue, 22 Dec 2020 11:28:43 +0100https://ask.sagemath.org/question/54836/Is it possible to substitute $U^\prime$ to $D_0(U)$ ?https://ask.sagemath.org/question/54555/is-it-possible-to-substitute-uprime-to-d_0u/The result of this code
var('x y p w0 g c')
assume(p>=0)
assume(p<=1)
U=function('U')(x)
EU(x,y,p)=p*U(x)+(1-p)*U(y)
show(EU(w0,g*w0-c,p))
show(diff(EU(w0,g*w0-c,p),w0))
uses $D_0(U)$ for the first order derivative of $U$. Is it possible to substitute $U^\prime$ to $D_0(U)$, to keep the path with textbook notations ?CyrilleFri, 04 Dec 2020 15:18:11 +0100https://ask.sagemath.org/question/54555/Substitute a function in a formal derivativehttps://ask.sagemath.org/question/54543/substitute-a-function-in-a-formal-derivative/This gives a nice result.
var('p w0 c g dc dg dp dw0')
EUa=function('EUa')(p,w0,c,g)
EUa_c=diff(EUa,c)
EUa_g=diff(EUa,g)
#
EUna=function('EUna')(p,w0,c,g)
EUna_g=diff(EUna,g)
EUna_c=diff(EUna,c)
##
dEUa=EUa_c*dc + EUa_g*dg
dEUna=EUna_c*dc + EUna_g*dg
###
show(EUa)
show(EUna)
show(dEUa)
show(dEUna)
sol=solve(dEUa==dEUna, dg)
sol=(sol[0]/dc).full_simplify()
show(sol)
But now, I would like to substitute to `EUa(p,w0,c,g) = p*U(w0)+(1-p)*U(0)` and `EUna(p,w0,c,g) = p*U(w0-c)+(1-p)*U(g*w0-c)` then, later change the unknown function `U(w)` to say `ln(w)` or `w^(1/2)`. I suppose I need to define first a function `U=function('U')(w)` after to define `w` as a variable. But all my tentatives fail.CyrilleThu, 03 Dec 2020 18:32:39 +0100https://ask.sagemath.org/question/54543/Formal implicit differentiationhttps://ask.sagemath.org/question/50991/formal-implicit-differentiation/As my question was poorly asked, I rewrite it.
I was searching for the code of first order and second order differentiation of an implicit function. Finally I found and post it.CyrilleFri, 24 Apr 2020 18:41:04 +0200https://ask.sagemath.org/question/50991/Composition of piecewise functionhttps://ask.sagemath.org/question/54466/composition-of-piecewise-function/[Remark: This is not a question but I do not know how to signal a mistake in the doc.
[http://fe.math.kobe-u.ac.jp/icms2010-dvd/SAGE/www.sagemath.org/doc/reference/sage/functions/piecewise.html](http://fe.math.kobe-u.ac.jp/icms2010-dvd/SAGE/www.sagemath.org/doc/reference/sage/functions/piecewise.html)
uses `Piecewise` which leads to an error, not `piecewise` which is good.]
Here is my question:
This code does exactly what I expect
A = 1000
g(x) = x^2
f = piecewise([[[1, 1], (A/12)],
[[2, 2], (A/(12 - 1) - 1*10)],
[[3, 3], (A/(12 - 2) - 2*10)]])
show(f(1), ", ", f(2), ", ", f(3))
fg = piecewise([[[1, 1], g(A/12)],
[[2, 2], g(A/(12 - 1) - 1*10)],
[[3, 3], g(A/(12 - 2) - 2*10)]])
show(fg(1), ", ", fg(2), ", ", fg(3))
but I have a lot of `g(x)` to compose with `f` so I would like
to know if there is a way to define a composition of functions
for piecewise functions (here defined on subset of `ZZ`).
There is also the problem where I have a function `h`
which is itself a piecewise function on the same set and I want
fgh = piecewise([[[1, 1], h(1)*g(A/12)],
[[2, 2], h(2)*g(A/(12 - 1) - 1*10)],
[[3, 3], h(3)*g(A/(12 - 2) - 2*10)]])
show(fg(1), ", ", fg(2), ", ", fg(3))CyrilleMon, 30 Nov 2020 16:53:05 +0100https://ask.sagemath.org/question/54466/sagemath fails to solve an equation and inequationhttps://ask.sagemath.org/question/54131/sagemath-fails-to-solve-an-equation-and-inequation/I do not understand why
var('R','p','x')
sol1=solve(R^(1/3)*p == x^(1/3),x)
show(sol1)
this work but this fails to isolate $x$
var('R','p','x')
sol1=solve(R^(1/3)*p <= x^(1/3),x)
show(sol1)
And that
var('R','p','x')
sol2=solve(0 == (R-x)^(1/3)*p + (1-p)* (-x)^(1/3),x)
show(sol2)
doesn't find $x$. And, as a consequence, of cours this :
var('R','p','x')
sol2=solve(0 <= (R-x)^(1/3)*p + (1-p)* (-x)^(1/3),x)
show(sol2)
fails. I have tried all simplification ways.CyrilleFri, 06 Nov 2020 12:58:08 +0100https://ask.sagemath.org/question/54131/From indexed variables to stringshttps://ask.sagemath.org/question/54026/from-indexed-variables-to-strings/ I can easily generate a list of variables with
xx = var("x", n=10, latex_name="x")
but I have many questions about this
1) `nc` is the number of variables needed. Say I need variables indexed from 10 to 20, not from 0 to 20. Am I obliged to
generate all 20 variables and let appart the 10 firsts (I have found nothing on options like n=, could it be a range ?).
2) if I have generated the following list `x=[x_1, x_2, x_3, x_4, x_5]` how may i transform it in a list of strings `x=['x_1', 'x_2', 'x_3', 'x_4', 'x_5']`
3) and what if I need to change the name of certain variable as ` 'x_3'-->'\\epsilon_2'` CyrilleSun, 25 Oct 2020 18:40:37 +0100https://ask.sagemath.org/question/54026/Creating sublist according countinuous intervalshttps://ask.sagemath.org/question/52066/creating-sublist-according-countinuous-intervals/I have a list of number say
`l = [1.25, 2.46, 3.99, 4, 5, 6, 7.12, 8.76 ,9.34, 10.42, 11.5, 12.]`
I have a list of real intervals
`Cl=[[0, 5),[5, 10),[10, 15)]`
How to create sublists of l according to the intervals in Cl ? If I was work in N there will be no difficulties.CyrilleThu, 18 Jun 2020 10:49:52 +0200https://ask.sagemath.org/question/52066/Replace all numbers < e-n by 0https://ask.sagemath.org/question/51784/replace-all-numbers-e-n-by-0/ As always two question in one.
F = random_matrix(RR,7,50)
import numpy as np
covMatrix = np.cov(F,bias=True)
Ω=matrix(covMatrix)
Λ=Ω.inverse()
Ω*Λ
1) Is there a way to ask Sama (nicname for SAgeMAth more elegant than SM -- a wink) to overcome the number less than e-n and replace it by 0 --- I have found a way : to use `change_ring(QQ)` but I want to know if therre is another way.
2) is there a way to ask Sama to display only n decimal digit.CyrilleSat, 06 Jun 2020 11:38:15 +0200https://ask.sagemath.org/question/51784/general implicit differentiationhttps://ask.sagemath.org/question/51519/general-implicit-differentiation/Recently i have been helped to write an implicit function differentiator (nice neologism isn't it). Here is the code
def implicit_derivative(V):
var("dw1, dw2")
V_w1 = diff(V, w1)
V_w2 = diff(V, w2)
# Differential
dV = V_w1 * dw1 + V_w2 * dw2
# Dérivée du premier ordre
sol=solve(dV==0, dw2)
impder=(sol[0]/dw1)
return impder
This work without difficulty for $V$ function of $w_1$ and $w_2$. But if my variables are $x$ and $y$ or say $\chi$ and $\zeta$. It will not work. I have not found the mechanism to define a general function not dependant of the name of its arguments. And here there is a second problem to find thway to associate the increase d... to its correlative argument that is if I use $\chi$ as the first variable $d\chi$ must substitute to $dw_1$.CyrilleSat, 23 May 2020 17:11:32 +0200https://ask.sagemath.org/question/51519/Strange behaviour in simplifying a functionhttps://ask.sagemath.org/question/51482/strange-behaviour-in-simplifying-a-function/ I am developping a long notebook to master Sage. But each time I fall on a problem. This time
p, D, w_0, x, I = var('p, D, w_0, x, I')
β = var('beta')
π = var('pi')
w00=8
D1=6
p1=0.5
A = matrix(SR, 2, 2, [[w_0, 1],[w_0-π,1]])
y = vector([w_0-D, w_0-D-π+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, π, w_0)
solb=sol[1].full_simplify().function(D, π, I, w_0)
f=(sola*x + solb).function(x, D, π, I, w_0)
g=f(x, D, β*I*(1-p), I, w_0).factor().collect(x).simplify().function(x, D, β, p, w_0)
h(x, D, p, w0)=g(x, D, 1, p, I, w_0).collect(D).collect(x).simplify()
show(f)
show(g)
show(h)
1) this is the main question : You can observe that `g` is independanr of `I`. But `h` is `g` with $\beta = 1$. So why `I` does reappear in h ?
2) How could we explain **SM** to write the slope of the 3 curves as I would write them in a sheet of paper ? CyrilleThu, 21 May 2020 19:57:45 +0200https://ask.sagemath.org/question/51482/Substitution in implicit functionhttps://ask.sagemath.org/question/51390/substitution-in-implicit-function/ This is the code to the implicit differentiaion of a function from the theoretical point of view
var("w1, w2, a, p")
EU(w1, w2, a, p)= p*w1^a+ (1-p)*w2^a
var("dw1, dw2")
V_w1 = diff(V, w1)
V_w2 = diff(V, w2)
# Differential
dV = V_w1 * dw1 + V_w2 * dw2
show("dV ="+latex(dV))
# Dérivée du premier ordre
sol=solve(dV==0, dw2)
show(sol[0]/dw1)
Now without to be obliged to rewrite all the commands, I would like to apply this procedure to the EU function or any other function. I have tried to use `dV.substitute_function(V, EU)` and `(sol[0]/dw1).right_hand_side()` but without success. I have an amplified problem for the second order derivative since I am nosure of my formulation due to the fact that one must substitute the first order derivative inside derivation.
CyrilleTue, 12 May 2020 18:09:05 +0200https://ask.sagemath.org/question/51390/Desattribution of a value to a variablehttps://ask.sagemath.org/question/51389/desattribution-of-a-value-to-a-variable/ Suppose I have attributed to `a` the value 3. But for the following operation I want to use anew `a` as a variable how should I operate, redefine `a` ?CyrilleTue, 12 May 2020 16:53:36 +0200https://ask.sagemath.org/question/51389/Full simplification of power doesn't workhttps://ask.sagemath.org/question/51359/full-simplification-of-power-doesnt-work/ x, a =SR.var('x a')
Uf1= x^a
ar1_x=diff(Uf1, x).full_simplify()
ar1_xx=diff(Uf1, x,2)
raar1 = -diff(Uf1, x,2)/diff(Uf1, x).full_simplify()
show(LatexExpr("U^{'}(x) ="+latex(ar1_x)))
show(LatexExpr("U^{''}(x) ="+latex(ar1_xx)))
show(LatexExpr("R_a(x) ="+latex(raar1)))
Why raar1 is not fully simplified ?CyrilleSun, 10 May 2020 00:22:33 +0200https://ask.sagemath.org/question/51359/Simplification failshttps://ask.sagemath.org/question/51052/simplification-fails/1) I have tried nearly all simplification methods, expansion, factorization, collect... on the following code for `Ra1`
var("x,a")
Ra1 = -diff(x^a, x,2)/diff(x^a, x)
show(Ra1)
but the self-evident simplification doesn't work. I wonder why. I also have tried to add assumption even I do not see why since it's only algebra
2) Is there a way to ask SM to factor on a variable ?CyrilleMon, 27 Apr 2020 11:18:46 +0200https://ask.sagemath.org/question/51052/Choosing the way a function is displayedhttps://ask.sagemath.org/question/50953/choosing-the-way-a-function-is-displayed/1) I have the following function `z=-(D*p-p*x - D + w0)/ (p-1)`. Is it possible to display it as `-(p/(1-p))*x + ((w0-D*(1-p)))/(1-p)`?
2) Can I select a part a this function --- the factor of `x`, `x` and the last part ?CyrilleThu, 23 Apr 2020 12:12:23 +0200https://ask.sagemath.org/question/50953/Strange behavior of bool()https://ask.sagemath.org/question/50942/strange-behavior-of-bool/Here is my code
var("w0, pi, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show(f(x, D, pi, I, w0))
f_x = f.diff(x).full_simplify()
show(f_x)
f_I = f.diff(I).full_simplify()
show(f_I)
Now, I make some assumptions and I verify the sign of $f_x$ and $f_I$.
assume(I, "real")
assume(pi, "real")
assume(I > pi)
bool(f_x < 0)
assume(w0, "real")
assume(x, "real")
assume(w0 > x)
bool(f_I > 0)
What is weird is that the result doesn't change should I ask for `bool(f_x < 0)` or ` bool(f_x > 0)` and the same for $f_I$. I know that my question looks like an already asked question "symbolic functions and bool". But this time the expressions are elementary.CyrilleThu, 23 Apr 2020 06:41:02 +0200https://ask.sagemath.org/question/50942/Evaluation of a function and it's inverse with parametershttps://ask.sagemath.org/question/50878/evaluation-of-a-function-and-its-inverse-with-parameters/The following code works perfectly :
var('W1, W2, Ub, p')
a, x, y = SR.var('a,x,y')
W2=W
U(x)=x^a
assume(a, 'real')
assume(a, 'noninteger') # or alternatively 'integer'
assume(x, 'real')
assume(y, 'real')
assume(x > 0)
assume(y > 0)
U(x).substitute(x==y)
show(U(x))
V=solve(x == U(y), [y])[0].rhs().function(x)
show(V)
VV=((Ub-p*U(W2))/(1-p))^(1/a)
show(VV)
But now I want to be also able to attribute some values to the parameters and the variable to achieve an evaluation and plot according to the parameter values. I need the function and it's inverse. I have seen the methode `lambda x` in the documentation but it's end with an error.CyrilleMon, 20 Apr 2020 19:13:36 +0200https://ask.sagemath.org/question/50878/