Skip to content

Project 3 - Q3 #31

Closed
evg16108 opened this issue Apr 3, 2020 · 3 comments
Closed

Project 3 - Q3 #31

evg16108 opened this issue Apr 3, 2020 · 3 comments

Comments

@evg16108
Copy link

evg16108 commented Apr 3, 2020

I am trying to do #3 on the project and I have defined the f_m function as follows:
image
I think there may be something wrong with this because when I use incsearch on it I get this:
image

@arr16112
Copy link

arr16112 commented Apr 3, 2020

At first glance I see a problem with the definition of tf. You're dividing by dmdt which preciously wasn't changing so it worked but in this case it is changing.

@evg16108
Copy link
Author

evg16108 commented Apr 3, 2020

I think there may be something wrong with my incsearch function:
image

@arr16112
Copy link

arr16112 commented Apr 3, 2020

I was having the same problem. This is what I got
/code/
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 = np.zeros(ns)
for i in range(ns):
f[i] = func(x[i])
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

/code/

@evg16108 evg16108 closed this as completed Apr 3, 2020
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants