Plot and function with three variables in python

An equation which is represent as below

sin(x)*sin(y)*sin(z)+cos(x)*sin(y)*cos(z)=0

I know the code to plot function for z=f(x,y) using matplotlib but to plot above function I don’t know the code, but I tried MATLAB MuPad code which is as follows

Plot(sin(x)*sin(y)*sin(z)+cos(x)*sin(y)*cos(z),#3d)

Upvotes: 1

Views: 3578

Answers (2)

J Arun Mani
J Arun Mani

Reputation: 620

Please don't mistake me, but I think your given equation to plot can be reduced to a simple 2D plot.

sin(x)*sin(y)*sin(z)+cos(x)*sin(y)*cos(z) = 0
sin(y)[sin(x)*sin(z)+cos(x)*cos(z)] = 0
sin(y)*cos(x-z) = 0
Hence sin(y) = 0 or cos(x-z)=0
Hence y = n*pi (1) or x-z=(2*n + 1)pi/2
Implies, x = z + (2*n + 1)pi/2 (2)

For (1), it will be a straight line (the plot of y vs n) and in second case, you will get parallel lines which cuts x-axis at (2*n + 1)pi/2 and distance between two parallel lines would be pi. (Assuming you keep n constant).

Assuming, your y can't be zero, you could simplify the plot to a 2D plot with just x and z.

And answering your original question, you need to use mplot3d to plot 3D plots. But as with any graphing tool, you need values or points of x, y, z. (You can compute the possible points by programming). Then you feed those points to the plot, like below.

from mpl_toolkits import mplot3d

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = plt.axes(projection="3d")
xs = [] # X values
ys = [] # Y values
zs = [] # Z values
ax.plot3D(xs, ys, zs)
plt.show()

Upvotes: 0

asmeurer
asmeurer

Reputation: 91480

This will be much easier if you can isolate z. Your equation is the same as sin(z)/cos(z) = -cos(x)*sin(y)/(sin(x)*sin(y)) so z = atan(-cos(x)*sin(y)/(sin(x)*sin(y))).

Upvotes: 1

Related Questions