Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Invalid Syntax Linw 1 [closed]

$
0
0

I would like to ask if how I am going to remove my invalid syntax in my code

I just want to know if what would be the solution for the invalid syntax.

import numpy as npdef bisection_method(f, a, b, tol=ie-6, max_iter=100):""""    Bisection method for finnding the root of a function f(x)=0.f        Parameters:    f (function): Function for which we are finding the root.    a (float): Start of interval.    b (float): End of interval.    tol (float): Tolerance for stopping criterion.    Returns:    x (float): Estimated root.    n (int): Number of iterations."""    if f(a) * f(b)>0:        raise ValueError("Fumction must have different signs at a and b")    n=0    while (b-a) / 2 > tol and n < max_iter:        c=(a+b) /2        if f(c) == 0:            return c, n        elif f(a) * f(c) < 0:            b=c        else:            a=c        n += 1    return (a + b) / 2, nf= lambda x: x**3 - 2*x**2 -5root, iterations = bisection_method(f, 2, 3)print(f"Root: (root), Iterations: (iterations)"

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>