tmpMM

1117 days ago by jlbravo

f(x,y)=x^2*y^2+y^4+x^2+x*y niveles=contour_plot(f(x,y),(x,-0.4,0.4),(y,-0.4,0.4), fill=False, cmap='hsv',labels=True, label_fmt="%1.2f", label_colors='black',contours=[0,0.1,0.005,0.02,0.05,-0.01,0.2,0.3,0.4,0.6,0.8]) f.show();niveles.show(figsize=5) 
       

plot3d((f(x,y)+0.1)^0.2,(x,-0.5,0.5),(y,-0.5,0.5)) 
       
Sleeping...
If no image appears re-execute the cell. 3-D viewer has been updated.
g=f.diff();show(g(x,y)) 
       
grafica=implicit_plot(g(x,y)[0]==0,(x,-0.4,0.4),(y,-0.4,0.4),color="black",linestyle='dashed')+implicit_plot(g(x,y)[1]==0,(x,-0.4,0.4),(y,-0.4,0.4),color="black") grafica.show(figsize=5) 
       
J=g.diff();show(J(x,y)) 
       
J(-0.2,0.3) 
       
[ 2.18000000000000 0.760000000000000]
[0.760000000000000  1.16000000000000]
[ 2.18000000000000 0.760000000000000]
[0.760000000000000  1.16000000000000]
-g(-0.2,0.3) 
       
(0.136000000000000, 0.0680000000000000)
(0.136000000000000, 0.0680000000000000)
def NewtonEjemplo(g,J,p0): x0,y0=p0 for i in [1..5]: x0,y0=vector([x0,y0])+matrix(RDF,J(x0,y0)).solve_right(-g(x0,y0)) return x0,y0 
       
NewtonEjemplo(g,J,(-0.2,0.3)) 
       
(-0.145359538240913, 0.320600553961304)
(-0.145359538240913, 0.320600553961304)
points([NewtonEjemplo(g,J,(0.5,0.1))])+points([NewtonEjemplo(g,J,(-0.5,0.1))])+points([NewtonEjemplo(g,J,(0.5,-0.5))])+points([NewtonEjemplo(g,J,(0.5,0.5))])+points([NewtonEjemplo(g,J,(-0.1,0.1))])+niveles 
       
[NewtonEjemplo(g,J,(0.5,0.1)),NewtonEjemplo(g,J,(-0.5,0.1)),NewtonEjemplo(g,J,(0.5,-0.5)),NewtonEjemplo(g,J,(0.5,0.5)),NewtonEjemplo(g,J,(-0.1,0.1))] 
       
[(0.153569312730443, -0.338675342907213), (-0.145359538246247,
0.320600553973068), (0.145359546447232, -0.320600572060605),
(-0.145388206310154, 0.320663783239632), (0.000000000000000,
0.000000000000000)]
[(0.153569312730443, -0.338675342907213), (-0.145359538246247, 0.320600553973068), (0.145359546447232, -0.320600572060605), (-0.145388206310154, 0.320663783239632), (0.000000000000000, 0.000000000000000)]
def colores(p,g,J): xs,ys=NewtonEjemplo(g,J,(p[0],p[1])) if (xs-0.145359538240913)^2+(ys+0.320600553961304)^2<0.01: return "green" if (xs+0.145359538240913)^2+(ys-0.320600553961304)^2<0.01: return "red" if xs^2+ys^2<0.01: return "yellow" return "blue" 
       
puntos_aleatorios=[(random()*0.8-0.4,random()*0.8-0.4) for i in [1..1000]] grafica+sum([point(p,color=colores(p,g,J)) for p in puntos_aleatorios])