Search code examples
pythongraphingexponential

Is it plausible to plug in equations for series in python?


I am trying to make an exponential function based on atmospheric pressure and height using python. i somehow have to be able to make the equation y = ( 1000 * e**( (-9.81 x / ( 78351 ) ) into a graph.

where y = 0 - 15 and x = 1000 y

while i could have python calculate each individual one, the point of the exercise is to be able to use the equation above as means for the graph.

Is there a way that i can have:

y_series = [0,1,2,3,4,5,6,7,8,9,10...]

and

x_series = [1000 * e**( -9.81 ( y_series ) / 78351 ) ?

I've tried multiple ways but keep getting : x and y must have same first dimension error.


Solution

  • Yes, it is:

    Syntax scheme:

    e        = 2.71                                                   # SET e
    y_series = range( 0, 16 )                                         # GEN y_series
    x_series = [ 1000 * e**( -9.81 * y / 78351 ) for y in y_series ]  # GEN x_series
    

    Output:

    >>> x_series
    [1000.0, 999.8751840341362, 999.7503836472979, 999.6255988375402, 999.5008296029192,
    999.3760759414907, 999.251337851311, 999.1266153304365, 999.0019083769238,
    998.87721698883, 998.7525411642123, 998.6278809011279, 998.5032361976348,
    998.3786070517907, 998.2539934616539, 998.1293954252827]