Ask Your Question

Cyrille's profile - activity

2020-05-25 09:36:29 -0500 asked a question Creating slave notebooks

I wonder if it si possible to construct a command to open a novel notebook inheriting of the properties of the main notebook an to communicate (go to a certainline of one of the two notebooks and to come back.

In such a way we could have a main notebook and each section would be a novel notebook

2020-05-23 22:00:55 -0500 commented answer general implicit differentiation

Thanks. Very nice code. Therer is a little 'bmol' look at the result of this

   χ, ζ =var('chi zeta')
   V=function('V')(χ, ζ)
   implicit_derivative(V)
2020-05-23 10:11:32 -0500 asked a question 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$.

2020-05-23 09:05:04 -0500 asked a question To add an arrow to an axe

Here is my attempt to add an arrow head to the axes of a graph. It seems not very effective since when I change the localization of the arrow the axes change also

far = plot(x^0.4,(x, 0, 10),ticks=[[], []])
far+= plot(1-exp(-0.4*x),(x, 0, 10),color="red",ticks=[[], []],ymin=0,ymax=3)
far+=text("$U$",(-.5,3),color="black", fontsize='small')
far+=text("$x$",(10.5,-.05),color="black", fontsize='small')
far+=text("$U=x^a$",(9.6,2.6),color="blue", fontsize='small', rotation=18)
far+=text("$U=1-e^{-0.4*x}$",(9.6,1.1),color="red", fontsize='small', rotation=5)
far+=arrow((10.4,0),(10.5,0),color='black',arrowsize=1, thickness =.5 )
far

In many ploting software arrows are option to objects. It seems that it is not the case in SM

2020-05-22 12:01:24 -0500 commented answer My error with @interact

Yes of course. I will erase plccp since it add nothing to the question. Thanks

2020-05-22 09:26:55 -0500 asked a question My error with @interact

I suppose it's not the custom to reuse a question, but the precedent was not a problem with Sagemath but with my computer

Here is a true question due to my incompetence. The following code leads onlys to the slider not the display of the function.

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)
show(g(x,D1,β,p1,w00))
@interact
def _(β=slider(1,5, step_size=1)):
    s1sol=solve(g(x,D1,β,p1,w00)==x, x)
    intersect2=s1sol[0].rhs()
    glou=plot(g(x,D1,β,p1,w00),(x, intersect2,w00))
    glou+=circle((intersect2,intersect2), .075, fill=True, edgecolor='red', facecolor='red')
    glou+=arc((w00,w00-D1),1.75,1.75,0,(3.14/2+3.14/4,3.14), linestyle="--", color="green")
    glou

What do I do wrong ?

2020-05-22 08:05:36 -0500 commented answer Is it possible to add arrow to arc() or other predefined plot

This is a boring solution. It should be an option.

2020-05-22 04:52:31 -0500 commented question Strange behaviour in simplifying a function

Thanks some time I would like to put aways my stupid questions.

2020-05-22 04:27:15 -0500 asked a question Problem with Jupyter displaying a picture

When things goes wrong usually Jupyter open a windows to print warning. Why some times when things are fine it does the same thing?

2020-05-21 12:57:45 -0500 asked a question 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 ?

2020-05-21 12:51:32 -0500 asked a question Is it possible to add arrow to arc() or other predefined plot

Is there a way to plot an arc or an elliptic arc with an arrow at the begining or/and at its end. The arrow could be pointing in either directions. I come from LaTex and pstricks where arrow head are options.

2020-05-19 12:18:12 -0500 asked a question How to lock the markdown cells

Is there a way to lock, with a code, the markdown cells. The idea is to send the notebook in such a way that markdown cells could not be change, but if I want to change them I can always do it.

2020-05-19 04:57:07 -0500 asked a question Changing color to RGB for Edgecolor...

Changing color to an other predetermined color is simple in plot(). Even to change to rgb(,,). But for other options than color as edgecolor or facecolor it seems more tricky. At last,I have not seen an exemple in the documentation.

2020-05-18 12:24:11 -0500 commented answer Substitution

Thank tmonteil. When I read your solution I feel stupid. This is so simple.

2020-05-18 12:22:42 -0500 commented answer Navigation inside a notebook

In a sens perfect, but I wonder if this is an uni-direction trick. It works if the reference is in the bottom of what is referenced. Is it true ? After some try it's a bi-directional command.

2020-05-18 08:10:50 -0500 asked a question Substitution

After some calculation I arrive to the following equation $\frac{Dp - D+ I}{D(P-1)}$.

Whichever be the command I use I cannot put it as $\frac{D(p - 1)+ I}{D(P-1)}$ or as $1-\frac{I}{D*(P-1)}$ or $1-\frac{I}{D}\frac{1}{(P-1)}$.

This last equation is the one of interest since I would like to solve $1-\frac{I}{D}\frac{1}{(P-1)}==0$ according to $\frac{D}{I}$.

Is there a way to use solve() acording to $\frac{D}{I}$ ? I have tried to substitue x with a form of substitute()for it, but it was an echec. I understand that substitue a ratio of 2 variables for one is a little bit complex.

2020-05-18 04:31:44 -0500 asked a question Navigation inside a notebook

Is there a way inside a notebook to make reference to a graphic or a calculation to navigate later to it and back.

2020-05-16 02:29:55 -0500 commented answer Valid Python identifier

The code has been provided And thanks for your help. I have tried your code of course it works. So I do not understand what happen.

2020-05-15 08:13:23 -0500 marked best answer Best way to read an external data file

What is the best way to read an external data file and to have the datas in sagemath format ? Should I add an add-on ?

2020-05-15 07:24:03 -0500 asked a question Valid Python identifier

For some days, I struggle with unicode. I haved followed the answer of my question "An error using unicode?" wich is to define

\pi(+TAB) = var('pi')
 x = var('x')

or (0I suppose)

\pi(+TAB), x = var('pi x')
 x = var('x')

but later, in my code I use \pi + Tab and I receive an error code The name "ϕ" is not a valid Python identifier (here it is "ϕ", because I have replaced pi by phi under the reasoning that pi was certainly a keyword in some packages). Is it one more time a problem of understanding ?

I have also tried

\pi(+TAB) = var('pii')
 x = var('x')

to try to by pass the difficulty.

Here is my code. It comes in some cells so I kept them.

%%html
<style>
body {
    font-family: "Palatino Linotype", cursive, sans-serif;
     background-color: rgb(252,251,251);
}
.prompt {
    font-family: "Palatino Linotype", cursive, sans-serif;
    font-size: 15px;
    min-width: 6em;
}
.input-prompt {
    color: rgb(108, 119, 188);
}
.output-prompt {
    color: rgb(20, 129, 106);
}
code, kbd, pre, samp, .CodeMirror {
    font-family:  "Palatino Linotype", cursive, sans-serif;
    font-size: 15px;
}

</style>

p, D, w_0, x, I = var('p, D, w_0, x, I')
β = var('beta')
ϕ = var('phi') 
w00=8
D1=6

% display latex

pl=line([(0,0), (10,10)], color="cyan",ticks=[[], []])
pl+=text("$W_2$",(-.5,10),color="black", fontsize='small')
pl+=text("$W_1$",(10,-.5),color="black", fontsize='small')
pl+=text("$Ligne$ $de$\n  $certitude$",(9,9),color="red", fontsize='small', rotation=45)
pl1=circle((w00,w00-D1), .075, fill=True, edgecolor='red', facecolor='red')
pl1+=line([(w00,0), (w00,w00-D1), (0,w00-D1)], linestyle="--")
pl1+=text("$W_0-D$",(-.75, w00-D1),color="black", fontsize='small')
pl1+=text("$W_0$",(w00,-.5),color="black", fontsize='small')
pl1+=text("$W_0$",(-.5, w00),color="black", fontsize='small')
pl1+=line([(w00,w00-D1), (w00,w00),(0,w00)], linestyle="--")
pl1+=circle((w00,w00), .075, fill=True, edgecolor='red', facecolor='red')
pl2=polygon([(0,0), (0,10), (10,10), (0,0)], fill=True, rgbcolor=(0.95,0.95,0.95),ticks=[[], []]) 
pl2+=text("$Loteries$ $inaccesibles$\n $par$ $inversion$ $d'états$",(4.5,9.1),color="red", fontsize='small', 
         background_color="white")
pl2+=polygon([(w00,0), (w00,w00), (10,10), (10,0)], fill=True, rgbcolor=(0.70,0.95,0.95),ticks=[[], []]) 
pl2+=text("$Loteries$ $inaccesibles$ $par$\n  $insuffisance$ $de$ $ressources$",(9.,5),color="red", 
         fontsize='small',background_color="white", rotation=90)
pl2+=polygon([(0,0), (w00-D1,w00-D1), (w00,w00-D1), (w00,0)], fill=True, rgbcolor=(0.95,0.75,0.95),ticks=[[], []]) 
pl2+=text("$Loteries$ $indésirable$ $par$\n $dégradation$ $des$ $deux$ $états$",(4.8,1),color="red", 
         fontsize='small', background_color="white", rotation=0)
pl12=pl+pl1+pl2
show(pl12)

And now comes the error

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(x, D, ϕ, I, w_0)=sola*x + solb

Here it is $\phi$ but I have the same problem with other characters.

2020-05-13 08:58:59 -0500 commented answer Substitution in implicit function

I have a little complementary question : this procedure is define for $w_1$, $w_2$ and then for $dw_1$ and $d_w2$. Ok but if my variables are say $x$ and $y$ I would like to work with $dx$ and $dy$. How to do in such a way to have an universal procedure ?

2020-05-12 13:57:19 -0500 received badge  Critic (source)
2020-05-12 12:04:24 -0500 commented question Substitution in implicit function

V=function('V')(w1, w2). The solution you propose works nicely but not for the theoretical presentation since my_procedure(V)return an error. I would like both but at last this is nice. Then I realize it suffice ta add return to your code to obtain what I was searching. Thanks

2020-05-12 11:09:05 -0500 asked a question 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.

2020-05-12 09:53:36 -0500 asked a question 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 ?

2020-05-12 05:42:33 -0500 asked a question An error using unicode?

Following the short answer of "Automatic substitution of unicode characters", the following code works nicely

%display unicode_art
π = var('pi')
solu=solve(π^2 - π==0, π)   
solu

But if this code works nicely too

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)
%display unicode_art
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, π, I, w0)=sola*x + solb
f(x, D, π, I, w0)

The use of unicode on the preceding code generates an error

%display unicode_art
π = var('pi')
var("w0, π, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-π,1]])
y = vector([w0-D, w0-D-π+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, π, I, w0)
solb=sol[1].full_simplify().function(D, π, I, w0)
f(x, D, π, I, w0)=sola*x + solb