0
$\begingroup$

I want to draw the curve made with euler() in the tube made with tube(). I guess I must go from cartesian coordinates to polar coordinates but I don't really the method. Can someone explain me please ?

import numpy as np
import matplotlib.pylab as plt

def tube():
    theta = np.linspace(0, np.pi/2, 30)

    x = np.cos(theta)
    y = np.sin(theta)
    z = x*0.8
    w = y*0.8

    plt.plot(z,w)
    plt.plot(x,y)
    plt.axis("equal")
    plt.show()

print plt.figure(1);tube()

TUBE

def euler():
    A, B, a = 40, 10, 2

    t  = 10  # time
    dt = 1e-3 # interval

    nbpt = int(t/dt)

    n = 1
    s = 1. # sign of the derivative, initially chosen
    y = [0]*nbpt # result

    while n < nbpt:
        yp2 = B - A*y[n-1]**a
        if yp2 < 0:
            s = -s
            n -= 1 # recalculating the previous value
        else:
            y[n] = y[n-1] + dt*s*np.sqrt(yp2)
            n += 1

    plt.plot(np.linspace(0,t,nbpt),y)
    plt.show()

print plt.figure(2);euler()

CURVE

  • 0
    maybe should be in computer science stack exhange2017-02-02
  • 1
    I went to stackoverflow but I think it is rather a problem of mathematics than a problem of programming.2017-02-02
  • 0
    Ok this could be2017-02-02
  • 0
    If your question is one of polar-cartesian conversion, you're in the right places. If so, can you please explain your mathematical processes?2017-02-02
  • 0
    I had an answer on stackoverflow and the cartesian-polar conversion works fine: http://stackoverflow.com/questions/42009252/how-to-draw-a-curve-in-cartesian-coordinates-in-a-semicircle-tube-in-polar-coord/42009927#42009927. Sorry I didn't expect to have a quick answer. Thank you anyway for trying to help ! :)2017-02-02

0 Answers 0