5

So I have this equation:

x^2 + 4*(z+10)^2 = e^(-0.05*z)

How cant I plot it using, for example, Matplotlib.pyplot and Numpy packages?

iury simoes-sousa
  • 1,440
  • 3
  • 20
  • 37
  • `x^2=e^(-0.05*z)-4*(z+10)^2` If `B=e^(-0.05*z)-4*(z+10)^2>0`, it has two solutions `x=sqrt(B)` and `x=-sqrt(B)`. Find the range of `z` for which `B>0` using dichotomy, then use `linespace` and plot two curves (`x,z` and `-x,z`), something like [this example](http://matplotlib.org/1.4.0/examples/mplot3d/lines3d_demo.html) – francis Apr 11 '15 at 20:00
  • I don't know if this is a solution to my problem. I was looking for something like what wolframalpha returns when I put this equation: [link](https://www.wolframalpha.com/input/?i=x%5E2+%2B+4*%28z%2B10%29%5E2+%3D+e%5E%28-0.05*z%29) – iury simoes-sousa Apr 11 '15 at 20:24

2 Answers2

7

My solution is: Calculate each side of equation for a given x and z gridded. Then I contour points that satisfy the equation. One side minus other equals to zero.

import numpy as np
import matplotlib.pyplot as plt

z = -np.linspace(9,15,100)
x = np.linspace(-26,26,1000)

x,z = np.meshgrid(x,z)

Z = -np.exp(-0.05*z) +4*(z+10)**2 
X = x**2


plt.contour(x,z,(X+Z),[0])
plt.xlim([-1.5,1.5])
plt.ylim([-11.5,-8.5])

Out

iury simoes-sousa
  • 1,440
  • 3
  • 20
  • 37
  • I'm trying to figure out how you came up with the parameters you passed to linspace. Sorry if this should be obvious! – JawguyChooser Mar 03 '17 at 19:35
  • Sorry. This is not obvious. It depends on the ellipse equation that you're using (the center of the ellipse and axis lenght). I just calculated to some values by test and adapted to my problem. – iury simoes-sousa Apr 19 '17 at 15:31
1

Use the plot_implicit function of sympy http://docs.sympy.org/latest/modules/plotting.html or use Sage http://www.sagemath.org/.

Edward Doolittle
  • 4,002
  • 2
  • 14
  • 27