I´m looking for the shape of a cistern using the Newton Raphson method. I´ve written this code asking for the graphic too. But when I want to use the function plot surface said that must to be 2 dimensional, and I don´t know how to fix it.
If it would work should it show me the minimum optimal X, y and Z to build the cistern.
This is my code
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import scipy as sci
"""
Para obtener el minimo hay que encontrar las derivadas 1eras e
igualarlas a 0
Cada una de esas 3 ecuaciones derivadas serán las que se usaraán para
armar el sistema
"""
def f_1(x,y,z):
return 2400*(z**2)*(x**2)*y+2500*(x**2)*(y**2)*z-510000
def f_2(x,y,z):
return 2400*(z**2)*(y**2)*x+2500*(x**2)*(y**2)*z-510000
def f_3(x,y,z):
return 2400*(z**2)*(x**2)*y+2400*(z**2)*(y**2)*x-510000
fig = plt.figure()
ax = fig.add_subplot( projection='3d')
x = y=z = np.linspace(0,20,100)
X, Y , Z=np.meshgrid(x,y,z)
zs1= np.array([f_1(x,y,z) for x,y,z in zip(np.ravel(X), np.ravel(Y),np.ravel(Z))])
Z1 = zs1.reshape(X.shape)
zs2= np.array([f_2(x,y,z) for x,y,z in zip(np.ravel(X), np.ravel(Y),np.ravel(Z))])
Z2 = zs2.reshape(X.shape)
zs3= np.array([f_3(x,y,z) for x,y,z in zip(np.ravel(X), np.ravel(Y),np.ravel(Z))])
Z3 = zs3.reshape(X.shape)
ax.plot_surface(X, Y, Z)
plt.hold(True)
ax.plot_surface(X, Y, Z)
ax.plot_surface(X, Y, Z)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
p=np.array([5,5,5 ])
tol=1E-5
iter=500
k=1
punto_nuevo=np.copy(p)
def jacobiano(x,y,z):
df1_x=4800*(y**2)*z*x+5000*(y**2)*z*x
df1_y=2400*(x**2)*(z**2)+5000*(x**2)*z*y
df1_z=4800*(x**2)*z*y+2500*(y**2)*(x**2)
df2_x= 2400*(y**2)*(z**2)+5000*(y**2)*z*x
df2_y=4800*(z**2)*y*x+5000*(x**2)*z*y
df2_z=4800*(y**2)*z*x+2500*(y**2)*(x**2)
df3_x=4800*(y**2)*z*x+2400*(y**2)*(z**2)
df3_y=2400*(z**2)*(z**2)+4800*(z**2)*y*x
df3_z=4800*(x**2)*z*y+4800*(y**2)*z*x
return np.array([[df1_x ,df1_y,df1_z],[df2_x ,df2_y,df2_z],[df3_x ,df3_y,df3_z]])
def funcion(x,y,z):
f1=2400*(z**2)*(x**2)*y+2500*(x**2)*(y**2)*z-510000
f2=2400*(z**2)*(y**2)*x+2500*(x**2)*(y**2)*z-510000
f3=2400*(z**2)*(x**2)*y+2400*(z**2)*(y**2)*x-510000
return np.array([f1,f2,f3])
#se realizan las iteraciones tantas veces como k sea menor a la canidad de iteraciones propuestas
while k<iter:
vector=np.linalg.solve(jacobiano(p[0],p[1],p[2])),-funcion(p[0],p[1],p[2])
punto_nuevo=p+vector
if np.linalg.norm(punto_nuevo-p)<tol:
break
p=np.copy(punto_nuevo)
print(p)
k=k+1
print('La raiz es = ' ,p)
If it would work should it show me the minimum optimal X, y and Z to build the cistern.