Skip to content

Project 3 Questions #18

Open
jmr15122 opened this issue Mar 26, 2020 · 7 comments
Open

Project 3 Questions #18

jmr15122 opened this issue Mar 26, 2020 · 7 comments

Comments

@jmr15122
Copy link

More of a question for Dr. Cooper, but in Problem 2 for project three, we are asked to 'Demonstrate that the solutions converge to equation (2.b) the Tsiolkovsky equation' as was asked in part one. But, this analytical solution neglects drag and gravity whereas we are now explicitly including these considerations with the new function called rocket . Is this simply a typo? Do you want us to make the comparison without the expectation of having the solutions converge?

I suspect it is a type because the next part of the problem is comparing the rocket and simple rocket solutions for the maximum height achieved, but just want to be sure.

Thanks.

@jmr15122
Copy link
Author

Along a similar vein in terms of clarification, we are asked to solve for the dmdt associated to a particular maximum (detonation) height. Should we be using the rocket function or the simplerocket function for this?

@jmr15122 jmr15122 changed the title Project 3 Clarification Project 3 Questions Mar 29, 2020
@jmr15122
Copy link
Author

Continuing on with the Project 3 questions that I have run into, I also have been having some issues using the incsearch function. When I try to call it on f_m, it doesn't seem to work properly, citing a type error. Outside of incsearch, f_m works fine, returning the error as expected and I have successfully used it in the mod_secant function as well. Below is the output error for my method call along with my definition of f_m. Has anyone seen this issue too? Any ideas for how to fix it?

image

image

@mpk15003
Copy link

in response to your first question, I am having the same issue. In problem 1 of the project my numerical solution converged to the Tsiokovsky equation. In problem 2, my results do not converge because it takes gravity and drag into account. I'm assuming that the results will not converge like they did in the first problem because the velocities from the rocket and the simplerocket integrations will differ significantly.

@rcc02007
Copy link
Owner

More of a question for Dr. Cooper, but in Problem 2 for project three, we are asked to >'Demonstrate that the solutions converge to equation (2.b) the Tsiolkovsky equation' as >was asked in part one. But, this analytical solution neglects drag and gravity whereas we >are now explicitly including these considerations with the new function called rocket . Is >this simply a typo? Do you want us to make the comparison without the expectation of >having the solutions converge?

The numerical result should converge if dm/dt >> mg+c*v^2, but you're right the answers should be different

@job15103
Copy link

job15103 commented Apr 2, 2020

jake, im having similar issues with the incsearch function. i cannot seem to get it to produce an answer for me. My f_dm function works as expected, but the incsearch function cannot work with it for some reason. here is my function and incsearch, and the output I get

def f_dm(dmdt,m0=0.25, c=0.18e-3, u=250):
    ''' define a function f_m(dmdt) that returns 
    height_desired-height_predicted[-1]
    here, the time span is based upon the value of dmdt
    
    arguments:
    ---------
    dmdt: the unknown mass change rate
    m0: the known initial mass
    c: the known drag in kg/m
    u: the known speed of the propellent
    
    returns:
    --------
    error: the difference between height_desired and height_predicted[-1]
        when f_m(dmdt)= 0, the correct mass change rate was chosen
    '''
    
    mf = 0.05
    dm = m0-mf
    T = dm/dmdt
    g = 9.81
    dt = T/100
    
    N = 100

    #create the time interval for our specifications
    t = np.linspace(0, T, N)

    #set initial conditions of position and velocity
    y0 = 0
    v0 = 0

    #initialize solution array
    num_sol = np.zeros([N,3])

    #initialize first variables using our set initial conditions
    num_sol[0,0] = y0
    num_sol[0,1] = v0
    num_sol[0,2] = m0

    #solve and write to our solution array
    for i in range(N-1):
        num_sol[i+1] = rk2_step(num_sol[i], rocket, dt)
    
    error = num_sol[-1,0]-300
    
    return error

def incsearch(func,xmin,xmax,ns=50):
    '''incsearch: incremental search root locator
    xb = incsearch(func,xmin,xmax,ns):
      finds brackets of x that contain sign changes
      of a function on an interval
    arguments:
    ---------
    func = name of function
    xmin, xmax = endpoints of interval
    ns = number of subintervals (default = 50)
    returns:
    ---------
    xb(k,1) is the lower bound of the kth sign change
    xb(k,2) is the upper bound of the kth sign change
    If no brackets found, xb = [].'''
    x = np.linspace(xmin,xmax,ns)
    f = func(x)
    sign_f = np.sign(f)
    delta_sign_f = sign_f[1:]-sign_f[0:-1]
    i_zeros = np.nonzero(delta_sign_f!=0)
    nb = len(i_zeros[0])
    xb = np.block([[ x[i_zeros[0]+1]],[x[i_zeros[0]] ]] )

    
    if nb==0:
      print('no brackets found\n')
      print('check interval or increase ns\n')
    else:
      print('number of brackets:  {}\n'.format(nb))
    return xb

incsearch(lambda x: f_dm(x), 0.05, 0.4, ns=7)
Screen Shot 2020-04-02 at 12 37 04 PM

@jmr15122
Copy link
Author

jmr15122 commented Apr 3, 2020

John, I did not encounter that exact error, but I do see a difference in the definition of the incsearch function that I asked Dr Cooper about. It has to do with the function definition within incsearch. Here is what the fix is to make it work:
Replace f = func(x) with

f = np.zeros(ns)
for i in range(ns):
f[i] = func(x[i])

Try that and maybe it will work. I also just used F_dm when using incsearch rather than lambda x: f_dm, since the incsearch function uses the input to call the function

@job15103
Copy link

job15103 commented Apr 3, 2020

thanks jake! that worked perfectly!

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants