In [3]:
# ~~~~~~~-------------------------------------------~~~~~~~
# code propre à la fonction voulue : à personnaliser
# ~~~~~~~-------------------------------------------~~~~~~~
f(x,y)=exp(-y^2)+x^4-x^2
lenom="fonction n : coupe"
leratio=(1,1,1/4)
lacouleur="cyan"
(xmin,xmax)=(-2,2)
(ymin,ymax)=(-2, 2)
(zmin,zmax)=(-8, 8)
#----
def laregion(x,y,z):#domaine de definition
    return True
#----
domdom=False # True = afficher un domaine de contrainte
dom(x,y)=x^2+y^2-1 #laisser ainsi même si pas de domaine
lacouleurdom="blue"
(zmindom,zmaxdom)=(-5,5) #idem
#----
coupcoup=True #afficher ou non une coupe par un plan
coupe(x,y)=y-1.5

#~~~~~~~-------------------------------------------~~~~~~~
# fin du code propre à la fonction voulue
# ~~~~~~~-------------------------------------------~~~~~~~




# -------------------------------------------------------------------------------------




# -------------------------------------------
# calculs généraux
# -------------------------------------------

show(html("<h4>"+lenom+"</h4>"))    
from sage.manifolds.operators import *
E.<x,y> = EuclideanSpace()
F = E.scalar_field(f)
H=f(x,y).hessian()
show(html("<h5>paramètres généraux</h5>"))
T=table([["f",f],["grad f=",grad(F)[:]],["H=",H]],frame=True,align='center')
show(T)

# -------------------------------------------
# calcul des points critiques
# -------------------------------------------

Cr= solve([grad(f)[0]==0,grad(f)[1]==0],[x,y],solution_dict=True)
liste=[]
for critique in Cr:
    x_et_y_reels=(x(critique).imag()==0 and y(critique).imag()==0)
    x_et_y_avec_parametre=(len(x(critique).variables())>0 or len(y(critique).variables())>0)
    if(x_et_y_reels or x_et_y_avec_parametre): 
        liste.append(["(","x","=",x(critique),";","y","=",y(critique),")",H(critique)])        
show(html("<h5>points critiques</h5>"))
if (len(liste)!=0):
    show(table(liste))
else :
    show("pas de points critiques")
    
# -------------------------------------------
# surface 3D
# -------------------------------------------
h(x,y,z)=f(x,y)-z
lasurface=implicit_plot3d(h, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color=lacouleur,adaptive=True,mesh=True,
    region=laregion)
    
from sage.plot.plot3d.shapes import Text
lalegende=Text(str(f)).translate(xmin,ymin,zmin)
#lalegende=Text(pretty_print(str(f))).translate(xmin,ymin,zmin)

ledomaine=implicit_plot3d(dom, (x, xmin,xmax), (y, ymin, ymax), (z, zmindom, zmaxdom),
    aspect_ratio=leratio,color=lacouleurdom,adaptive=True,mesh=True,
    region=laregion)

lacoupe3d=implicit_plot3d(coupe, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color="green",adaptive=True,mesh=True,
    region=laregion)


# -------------------------------------------
# lignes de niveau
# -------------------------------------------

pas=(zmax-zmin)/20
import numpy as np
leslignes=contour_plot(
                      f, (x,xmin, xmax), (y,ymin, ymax),
                      fill=False, plot_points=550,
                      linewidths=0.5,#label_fmt="%1.0f",
                      cmap='winter',#'hsv'
                      labels=True,label_fmt=lambda x: "$%1.0f$"%x,
                      label_inline=True,label_fontsize=10,
                      label_inline_spacing=1,
                      label_colors='black',axes=True,
                      contours=np.arange(zmin,zmax,pas)
                      )
                      #contours=[-1,0,1]) #pour choix manuel des valeurs de k

ladroite=implicit_plot(coupe, (x,xmin, xmax), (y,ymin, ymax))
ledomaine2d=implicit_plot(dom, (x,xmin, xmax), (y,ymin, ymax))

# -------------------------------------------
# enfin, les show
# -------------------------------------------
#show 3d

if (domdom and coupcoup):
    show(lasurface+ledomaine+lalegende+lacoupe3d)
elif domdom:
    show(lasurface+lalegende+ledomaine)
elif coupcoup:
    show(lasurface+lalegende+lacoupe3d)
else:
    show(lasurface+lalegende)


#show 2d
if (domdom and coupcoup):
    show(leslignes+ladroite+ledomaine2d)
elif domdom:
    show(leslignes+ledomaine2d)
elif coupcoup:
    show(leslignes+ladroite)
else:
    show(leslignes)

# -------------------------------------------
# fin
# -------------------------------------------

fonction n : coupe

paramètres généraux
f \(\left( x, y \right) \ {\mapsto} \ x^{4} - x^{2} + e^{\left(-y^{2}\right)}\)
grad f= \(\left[4 \, x^{3} - 2 \, x, -2 \, y e^{\left(-y^{2}\right)}\right]\)
H= \(\left(\begin{array}{rr} 12 \, x^{2} - 2 & 0 \\ 0 & 4 \, y^{2} e^{\left(-y^{2}\right)} - 2 \, e^{\left(-y^{2}\right)} \end{array}\right)\)
points critiques
( x = \(0\) ; y = \(0\) ) \(\left(\begin{array}{rr} -2 & 0 \\ 0 & -2 \end{array}\right)\)
( x = \(-\frac{1}{2} \, \sqrt{2}\) ; y = \(0\) ) \(\left(\begin{array}{rr} 4 & 0 \\ 0 & -2 \end{array}\right)\)
( x = \(\frac{1}{2} \, \sqrt{2}\) ; y = \(0\) ) \(\left(\begin{array}{rr} 4 & 0 \\ 0 & -2 \end{array}\right)\)
In [ ]:
 
In [4]:
# ~~~~~~~-------------------------------------------~~~~~~~
# code propre à la fonction voulue : à personnaliser
# ~~~~~~~-------------------------------------------~~~~~~~
f(x,y)=(x-1)*(y-2)*(x+y-6)
lenom="fonction B : réserve d'eau…<"
lacouleur="cornflowerblue"
leratio=(1,1,1/4)
(xmin,xmax)=(-2,6)
(ymin,ymax)=(-3, 8)
(zmin,zmax)=(-10, 10)
#----
def laregion(x,y,z):#domaine de definition
    return True
#----
domdom=False # True = afficher un domaine de contrainte
dom(x,y)=x^2+y^2-1 #laisser ainsi même si pas de domaine
lacouleurdom="blue"
(zmindom,zmaxdom)=(-5,5) #idem
#----
coupcoup=True #afficher ou non une coupe par un plan
coupe(x,y)=y-4



#~~~~~~~-------------------------------------------~~~~~~~
# fin du code propre à la fonction voulue
# ~~~~~~~-------------------------------------------~~~~~~~




# -------------------------------------------------------------------------------------




# -------------------------------------------
# calculs généraux
# -------------------------------------------

show(html("<h4>"+lenom+"</h4>"))    
from sage.manifolds.operators import *
E.<x,y> = EuclideanSpace()
F = E.scalar_field(f)
H=f(x,y).hessian()
show(html("<h5>paramètres généraux</h5>"))
T=table([["f",f],["grad f=",grad(F)[:]],["H=",H]],frame=True,align='center')
show(T)

# -------------------------------------------
# calcul des points critiques
# -------------------------------------------

Cr= solve([grad(f)[0]==0,grad(f)[1]==0],[x,y],solution_dict=True)
liste=[]
for critique in Cr:
    x_et_y_reels=(x(critique).imag()==0 and y(critique).imag()==0)
    x_et_y_avec_parametre=(len(x(critique).variables())>0 or len(y(critique).variables())>0)
    if(x_et_y_reels or x_et_y_avec_parametre): 
        liste.append(["(","x","=",x(critique),";","y","=",y(critique),")",H(critique)])        
show(html("<h5>points critiques</h5>"))
if (len(liste)!=0):
    show(table(liste))
else :
    show("pas de points critiques")
    
# -------------------------------------------
# surface 3D
# -------------------------------------------
h(x,y,z)=f(x,y)-z
lasurface=implicit_plot3d(h, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color=lacouleur,adaptive=True,mesh=True,
    region=laregion)
    
from sage.plot.plot3d.shapes import Text
lalegende=Text(str(f)).translate(xmin,ymin,zmin)
#lalegende=Text(pretty_print(str(f))).translate(xmin,ymin,zmin)

ledomaine=implicit_plot3d(dom, (x, xmin,xmax), (y, ymin, ymax), (z, zmindom, zmaxdom),
    aspect_ratio=leratio,color=lacouleurdom,adaptive=True,mesh=True,
    region=laregion)

lacoupe3d=implicit_plot3d(coupe, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color="green",adaptive=True,mesh=True,
    region=laregion)


# -------------------------------------------
# lignes de niveau
# -------------------------------------------

pas=(zmax-zmin)/20
import numpy as np
leslignes=contour_plot(
                      f, (x,xmin, xmax), (y,ymin, ymax),
                      fill=False, plot_points=550,
                      linewidths=0.5,#label_fmt="%1.0f",
                      cmap='winter',#'hsv'
                      labels=True,label_fmt=lambda x: "$%1.0f$"%x,
                      label_inline=True,label_fontsize=10,
                      label_inline_spacing=1,
                      label_colors='black',axes=True,
                      #aspect_ratio=leratio[1]/leratio[0],
                      fig_tight=False,aspect_ratio=1,#'automatic',
                        figsize=(4,4),
                      contours=np.arange(zmin,zmax,pas)
                      )
                      #contours=[-1,0,1]) #pour choix manuel des valeurs de k

ladroite=implicit_plot(coupe, (x,xmin, xmax), (y,ymin, ymax))
ledomaine2d=implicit_plot(dom, (x,xmin, xmax), (y,ymin, ymax))

# -------------------------------------------
# enfin, les show
# -------------------------------------------
#show 3d

if (domdom and coupcoup):
    show(lasurface+ledomaine+lalegende+lacoupe3d)
elif domdom:
    show(lasurface+lalegende+ledomaine)
elif coupcoup:
    show(lasurface+lalegende+lacoupe3d)
else:
    show(lasurface+lalegende)


#show 2d
if (domdom and coupcoup):
    show(leslignes+ladroite+ledomaine2d)
elif domdom:
    show(leslignes+ledomaine2d)
elif coupcoup:
    show(leslignes+ladroite)
else:
    show(leslignes)

show(leratio[0]/leratio[1])
# -------------------------------------------
# fin
# -------------------------------------------

fonction B : réserve d'eau…<

paramètres généraux
f \(\left( x, y \right) \ {\mapsto} \ {\left(x + y - 6\right)} {\left(x - 1\right)} {\left(y - 2\right)}\)
grad f= \(\left[{\left(2 \, x - 9\right)} y + y^{2} - 4 \, x + 14, x^{2} + 2 \, {\left(x - 1\right)} y - 9 \, x + 8\right]\)
H= \(\left(\begin{array}{rr} 2 \, y - 4 & 2 \, x + 2 \, y - 9 \\ 2 \, x + 2 \, y - 9 & 2 \, x - 2 \end{array}\right)\)
points critiques
( x = \(2\) ; y = \(3\) ) \(\left(\begin{array}{rr} 2 & 1 \\ 1 & 2 \end{array}\right)\)
( x = \(4\) ; y = \(2\) ) \(\left(\begin{array}{rr} 0 & 3 \\ 3 & 6 \end{array}\right)\)
( x = \(1\) ; y = \(5\) ) \(\left(\begin{array}{rr} 6 & 3 \\ 3 & 0 \end{array}\right)\)
( x = \(1\) ; y = \(2\) ) \(\left(\begin{array}{rr} 0 & -3 \\ -3 & 0 \end{array}\right)\)
\[\newcommand{\Bold}[1]{\mathbf{#1}}1\]
In [12]:
# ~~~~~~~-------------------------------------------~~~~~~~
# code propre à la fonction voulue : à personnaliser
# ~~~~~~~-------------------------------------------~~~~~~~
f(x,y)=x^2*y-y
lenom="fonction ab : CC2"
leratio=(1,1,1)
lacouleur="red"
(xmin,xmax)=(-2,2)
(ymin,ymax)=(-2,2)
(zmin,zmax)=(-2, 2)
#----
def laregion(x,y,z):#domaine de definition
    return True
#----
domdom=False # True = afficher un domaine de contrainte
dom(x,y)=x^2+y^2-1 #laisser ainsi même si pas de domaine
lacouleurdom="blue"
(zmindom,zmaxdom)=(-5,5) #idem
#----
coupcoup=False #afficher ou non une coupe par un plan
coupe(x,y)=y-0.5




#~~~~~~~-------------------------------------------~~~~~~~
# fin du code propre à la fonction voulue
# ~~~~~~~-------------------------------------------~~~~~~~




# -------------------------------------------------------------------------------------




# -------------------------------------------
# calculs généraux
# -------------------------------------------

show(html("<h4>"+lenom+"</h4>"))    
from sage.manifolds.operators import *
E.<x,y> = EuclideanSpace()
F = E.scalar_field(f)
H=f(x,y).hessian()
show(html("<h5>paramètres généraux</h5>"))
T=table([["f",f],["grad f=",grad(F)[:]],["H=",H]],frame=True,align='center')
show(T)

# -------------------------------------------
# calcul des points critiques
# -------------------------------------------

Cr= solve([grad(f)[0]==0,grad(f)[1]==0],[x,y],solution_dict=True)
liste=[]
for critique in Cr:
    x_et_y_reels=(x(critique).imag()==0 and y(critique).imag()==0)
    x_et_y_avec_parametre=(len(x(critique).variables())>0 or len(y(critique).variables())>0)
    if(x_et_y_reels or x_et_y_avec_parametre): 
        liste.append(["(","x","=",x(critique),";","y","=",y(critique),")",H(critique)])        
show(html("<h5>points critiques</h5>"))
if (len(liste)!=0):
    show(table(liste))
else :
    show("pas de points critiques")
    
# -------------------------------------------
# surface 3D
# -------------------------------------------
h(x,y,z)=f(x,y)-z
lasurface=implicit_plot3d(h, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color=lacouleur,adaptive=True,mesh=True,
    region=laregion)
    
from sage.plot.plot3d.shapes import Text
lalegende=Text(str(f)).translate(xmin,ymin,zmin)
#lalegende=Text(pretty_print(str(f))).translate(xmin,ymin,zmin)

ledomaine=implicit_plot3d(dom, (x, xmin,xmax), (y, ymin, ymax), (z, zmindom, zmaxdom),
    aspect_ratio=leratio,color=lacouleurdom,adaptive=True,mesh=True,
    region=laregion)

lacoupe3d=implicit_plot3d(coupe, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color="green",adaptive=True,mesh=True,
    region=laregion)


# -------------------------------------------
# lignes de niveau
# -------------------------------------------

pas=(zmax-zmin)/20
import numpy as np
leslignes=contour_plot(
                      f, (x,xmin, xmax), (y,ymin, ymax),
                      fill=False, plot_points=550,
                      linewidths=0.5,#label_fmt="%1.0f",
                      cmap='winter',#'hsv'
                      labels=True,label_fmt=lambda x: "$%1.0f$"%x,
                      label_inline=True,label_fontsize=10,
                      label_inline_spacing=1,
                      label_colors='black',axes=True,
                      #aspect_ratio=leratio[1]/leratio[0],
                      fig_tight=False,aspect_ratio=1,#'automatic',
                        figsize=(4,4),
                      contours=np.arange(zmin,zmax,pas)
                      )
                      #contours=[-1,0,1]) #pour choix manuel des valeurs de k

ladroite=implicit_plot(coupe, (x,xmin, xmax), (y,ymin, ymax))
ledomaine2d=implicit_plot(dom, (x,xmin, xmax), (y,ymin, ymax))

# -------------------------------------------
# enfin, les show
# -------------------------------------------
#show 3d

if (domdom and coupcoup):
    show(lasurface+ledomaine+lalegende+lacoupe3d)
elif domdom:
    show(lasurface+lalegende+ledomaine)
elif coupcoup:
    show(lasurface+lalegende+lacoupe3d)
else:
    show(lasurface+lalegende)


#show 2d
if (domdom and coupcoup):
    show(leslignes+ladroite+ledomaine2d)
elif domdom:
    show(leslignes+ledomaine2d)
elif coupcoup:
    show(leslignes+ladroite)
else:
    show(leslignes)

show(leratio[0]/leratio[1])
# -------------------------------------------
# fin
# -------------------------------------------

fonction ab : CC2

paramètres généraux
f \(\left( x, y \right) \ {\mapsto} \ x^{2} y - y\)
grad f= \(\left[2 \, x y, x^{2} - 1\right]\)
H= \(\left(\begin{array}{rr} 2 \, y & 2 \, x \\ 2 \, x & 0 \end{array}\right)\)
points critiques
( x = \(1\) ; y = \(0\) ) \(\left(\begin{array}{rr} 0 & 2 \\ 2 & 0 \end{array}\right)\)
( x = \(-1\) ; y = \(0\) ) \(\left(\begin{array}{rr} 0 & -2 \\ -2 & 0 \end{array}\right)\)
\[\newcommand{\Bold}[1]{\mathbf{#1}}1\]
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [3]:
# ~~~~~~~-------------------------------------------~~~~~~~
# code propre à la fonction voulue : à personnaliser
# ~~~~~~~-------------------------------------------~~~~~~~
f(x,y)=x^2*y-y
lenom="fonction ab bords : CC2"
leratio=(1/4,1/3,1/30)
lacouleur="red"
(xmin,xmax)=(-4,4)
(ymin,ymax)=(-4,4)
(zmin,zmax)=(-25, 25)
#----
def laregion(x,y,z):#domaine de definition
    return True
#----
domdom=True # True = afficher un domaine de contrainte
dom(x,y)=max_symbolic(abs(x),abs(y))-3 #laisser ainsi même si pas de domaine
lacouleurdom="blue"
(zmindom,zmaxdom)=(zmin,zmax) #idem
#----
coupcoup=False #afficher ou non une coupe par un plan
coupe(x,y)=y-0.5




#~~~~~~~-------------------------------------------~~~~~~~
# fin du code propre à la fonction voulue
# ~~~~~~~-------------------------------------------~~~~~~~




# -------------------------------------------------------------------------------------




# -------------------------------------------
# calculs généraux
# -------------------------------------------

show(html("<h4>"+lenom+"</h4>"))    
from sage.manifolds.operators import *
E.<x,y> = EuclideanSpace()
F = E.scalar_field(f)
H=f(x,y).hessian()
show(html("<h5>paramètres généraux</h5>"))
T=table([["f",f],["grad f=",grad(F)[:]],["H=",H]],frame=True,align='center')
show(T)

# -------------------------------------------
# calcul des points critiques
# -------------------------------------------

Cr= solve([grad(f)[0]==0,grad(f)[1]==0],[x,y],solution_dict=True)
liste=[]
for critique in Cr:
    x_et_y_reels=(x(critique).imag()==0 and y(critique).imag()==0)
    x_et_y_avec_parametre=(len(x(critique).variables())>0 or len(y(critique).variables())>0)
    if(x_et_y_reels or x_et_y_avec_parametre): 
        liste.append(["(","x","=",x(critique),";","y","=",y(critique),")",H(critique)])        
show(html("<h5>points critiques</h5>"))
if (len(liste)!=0):
    show(table(liste))
else :
    show("pas de points critiques")
    
# -------------------------------------------
# surface 3D
# -------------------------------------------
h(x,y,z)=f(x,y)-z
lasurface=implicit_plot3d(h, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color=lacouleur,adaptive=True,mesh=True,
    region=laregion)
    
from sage.plot.plot3d.shapes import Text
lalegende=Text(str(f)).translate(xmin,ymin,zmin)
#lalegende=Text(pretty_print(str(f))).translate(xmin,ymin,zmin)

ledomaine=implicit_plot3d(dom, (x, xmin,xmax), (y, ymin, ymax), (z, zmindom, zmaxdom),
    aspect_ratio=leratio,color=lacouleurdom,adaptive=True,mesh=True,
    region=laregion)

lacoupe3d=implicit_plot3d(coupe, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
    aspect_ratio=leratio,color="green",adaptive=True,mesh=True,
    region=laregion)


# -------------------------------------------
# lignes de niveau
# -------------------------------------------

pas=(zmax-zmin)/20
import numpy as np
leslignes=contour_plot(
                      f, (x,xmin, xmax), (y,ymin, ymax),
                      fill=False, plot_points=550,
                      linewidths=0.5,#label_fmt="%1.0f",
                      cmap='winter',#'hsv'
                      labels=True,label_fmt=lambda x: "$%1.0f$"%x,
                      label_inline=True,label_fontsize=10,
                      label_inline_spacing=1,
                      label_colors='black',axes=True,
                      #aspect_ratio=leratio[1]/leratio[0],
                      fig_tight=False,aspect_ratio=1,#'automatic',
                        figsize=(4,4),
                      contours=np.arange(zmin,zmax,pas)
                      )
                      #contours=[-1,0,1]) #pour choix manuel des valeurs de k

ladroite=implicit_plot(coupe, (x,xmin, xmax), (y,ymin, ymax))
ledomaine2d=implicit_plot(dom, (x,xmin, xmax), (y,ymin, ymax))

# -------------------------------------------
# enfin, les show
# -------------------------------------------
#show 3d

if (domdom and coupcoup):
    show(lasurface+ledomaine+lalegende+lacoupe3d)
elif domdom:
    show(lasurface+lalegende+ledomaine)
elif coupcoup:
    show(lasurface+lalegende+lacoupe3d)
else:
    show(lasurface+lalegende)


#show 2d
if (domdom and coupcoup):
    show(leslignes+ladroite+ledomaine2d)
elif domdom:
    show(leslignes+ledomaine2d)
elif coupcoup:
    show(leslignes+ladroite)
else:
    show(leslignes)

show(leratio[0]/leratio[1])
# -------------------------------------------
# fin
# -------------------------------------------

fonction ab bords : CC2

paramètres généraux
f \(\left( x, y \right) \ {\mapsto} \ x^{2} y - y\)
grad f= \(\left[2 \, x y, x^{2} - 1\right]\)
H= \(\left(\begin{array}{rr} 2 \, y & 2 \, x \\ 2 \, x & 0 \end{array}\right)\)
points critiques
( x = \(1\) ; y = \(0\) ) \(\left(\begin{array}{rr} 0 & 2 \\ 2 & 0 \end{array}\right)\)
( x = \(-1\) ; y = \(0\) ) \(\left(\begin{array}{rr} 0 & -2 \\ -2 & 0 \end{array}\right)\)
\[\newcommand{\Bold}[1]{\mathbf{#1}}\frac{3}{4}\]
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: