<jupyter_start><jupyter_text>define the functions derivative<jupyter_code>def derivative_for_root(x):
    a = 1.01
    b = -3.04
    return 2*a*x + b<jupyter_output><empty_output><jupyter_text>define primary work fxn<jupyter_code>def newton_raphson_root_finding(f, dfdx, x_start, tol):
    
    flag = 1
    
    imax = 10000
    
    i = 0
    
    x_old = x_start
    x_new = 0.0
    y_new = 0.0
    
    while(flag):
        x_new = x_old - f(x_old)/dfdx(x_old)
        print(x_new,x_old,f(x_old),dfdx(x_old))
        
        y_new = f(x_new)
        if(np.fabs(y_new)<tol):
            flag = 0
        else:
            x_old = x_new
            i += 1
        
        if(i>=imax):
            printf("Max iterations reached.")
            raise StopIteration('Stopping iterations after ',i)
            
    return x_new

x_start = 0.5
tolerance = 1.0e-6

print(x_start,function_for_root(x_start))

x_root = newton_raphson_root_finding(function_for_root,derivative_for_root,x_start,tolerance)
y_root = function_for_root(x_root)

s = "Root found with y(%f) = %f" % (x_root,y_root)
print(s)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11101243339253997, 'fraction_numerical': 0.022202486678507993, 'mean_word_length': 2.521875, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '157500', 'license': 'MIT', 'n_tokens_mistral': 475, 'n_tokens_neox': 448, 'n_words': 74, 'path': 'nr-root-finding-demo-Copy1.ipynb', 'repo_name': 'npurtell/astr-119-session-8', 'size': '1126'}