2

For example, how to plot sin(x^2 + y^2) = cos(x * y)?
It is hard to simplify this function to y = f(x).

I think this is not a duplicate to Is it possible to plot implicit equations using Matplotlib?, since my question is about y = f(x) and not z = f(x, y)

Howard
  • 217
  • 2
  • 12

1 Answers1

0

Contour function may be used:

import numpy as np
import matplotlib.pylab as plt

x = np.linspace(-1., 1.)
y = np.linspace(-1., 1.)[:, None] # y has to be 2d array
plt.contour(x, y.flatten(), np.sin(x*x+y*y) - np.cos(x*y))

plt.show()

enter image description here

pcu
  • 1,204
  • 11
  • 27
  • OP explicitely said they don't want `z = f(x, y)`. Why are you then answering by giving the solution for the case they don't want? Especially as there already was the link to the question present which shows the correct answer. – ImportanceOfBeingErnest Jul 14 '17 at 08:27
  • Where you find z? It is f(x,y)=0. – pcu Jul 15 '17 at 10:05
  • That's exactly my point. The code from your answer produces contours for `z = f(x, y)` with z equal to -0.8, -0.6, -0.4 etc., while the question is about `f(x,y)=0`. – ImportanceOfBeingErnest Jul 15 '17 at 10:12
  • Exactly! But you misunderstand something cos all these lines are satisfy to equation f(x,y)=0. Equation is trigonometric and have a lot of resolutions. Contour plot is allowed to show them with desired steps like here step is near 1/5.According to your thesis x^2+y^2=1 is a f(x,y)=z equation but it is doubtful. – pcu Jul 15 '17 at 11:49
  • You may surely call each of the lines a solution to `g(x,y)=0`. In that case however, `g` is different for each line. Say we have `F = sin(x**2 + y**2)` and `G=cos(x * y)`. The question looks for a solution to `f(x,y) = F-G==0`. Instead of providing that solution, you plot the solutions to `f(x,y)+0.8=0` (dark blue line), `f(x,y)+0.6 =0` (marine blue line) and so on. While you could write them as `g1(x,y)=f(x,y)+0.8=0`, `g2(x,y) = f(x,y)+0.6=0` etc., such that each of them solves `gi(x,y)=0`, this is not what the question is about. – ImportanceOfBeingErnest Jul 15 '17 at 12:28
  • Ok, you just want to put a minus – pcu Jul 17 '17 at 04:58
  • No I don't want to put a minus. – ImportanceOfBeingErnest Jul 17 '17 at 06:23