<jupyter_start><jupyter_text>Numerical Solution of Non-Linear Equations<jupyter_code>import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>General real functions<jupyter_code>from scipy.optimize import fsolve
def f(x): return x**2 - 1

fsolve(f, 0.5)
fsolve(f, -0.5)
fsolve(f, [-0.5, 0.5])<jupyter_output><empty_output><jupyter_text>Example<jupyter_code>def f(x): return np.sin(x)**10
fsolve(np.sin, 1)
fsolve(f, 1)
# Close answer, but not exact
def f(x): return 1/(x-1)
fsolve(f, 2, full_output = True)<jupyter_output><empty_output><jupyter_text>Complex roots of polynomials<jupyter_code>def f(x): return x * (1 + x**3) -1
fsolve(f, 1), fsolve(f, -1)
# Two real roots and two complex roots
np.roots([1, 0, 0, 1, -1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15120711562897077, 'fraction_numerical': 0.03430749682337993, 'mean_word_length': 6.959595959595959, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '618327', 'license': 'MIT', 'n_tokens_mistral': 346, 'n_tokens_neox': 329, 'n_words': 74, 'path': 'Numerical Solution of Non-Linear Equations.ipynb', 'repo_name': 'mkirby1995/Python_for_physical_modeling', 'size': '787'}