Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bisection method
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#python 3.6.9 print ("Hello, world!") ## Python3 implementation of Regula Falsi # Method for solving equations MAX_ITER = 1000000 # An example function whose solution # is determined using Regula Falsi Method. # The function is x^3 - x^2 + 2 def func( x ): return (x * x * x - x - 1) # Prints root of func(x) in interval [a, b] def regulaFalsi( a , b): if func(a) * func(b) >= 0: print("You have not assumed right a and b") return -1 c = a # Initialize result for i in range(MAX_ITER): # Find the point that touches x axis c = (a * func(b) - b * func(a))/ (func(b) - func(a)) # Check if the above found point is root if func(c) == 0: break # Decide the side to repeat the steps elif (func(c) * func(a)) < 0: b = c else: a = c print("The value of root is : " , '%.4f' %c) # Driver code to test above function # Initial values assumed a = 1 b = 1.5 regulaFalsi(a, b)
[
+
]
Show input
Absolute running time: 1.49 sec, cpu time: 1.99 sec, memory peak: 8 Mb, absolute service time: 1,64 sec
edit mode
|
history
|
discussion