Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fsolve over meshgrid
#1
Consider the equation given in the function eq. The aim is to solve the equation for z (which becomes a surface in 3-space) and plot it in a 3d plot. How would one solve for values of z over the meshgrid X,Y? The code below only gives the values of z along the line y=x.

import numpy as np
from mpl_toolkits import mplot3d
from scipy.optimize import fsolve

def eq(z,x,y):
    return x+2*y+z+np.exp(2*z)-1
X=Y=np.linspace(0,2,3)
X,Y=np.meshgrid(X,Y)
Z=[]
for x,y in zip(X,Y):
    Z.append(fsolve(eq,1,args=(x,y))[0])
    
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, np.asarray(Z), alpha=0.5);
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  fsolve giovanna 1 1,834 Aug-04-2019, 04:14 PM
Last Post: giovanna

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020