Determining Wien’s constant using bisection method and false position method. (Python Program)

 To determine Wien’s constant using Bisection Method and False position method.


Theory:




Bisection Method

# ----------------------------------------------
# Exp :2 To determine Wien ’s constant using bisection
# method and false position method .
# -----------------------------------------------
import numpy as np
import math
# ------------ equation --- ---- ----- ----- ---- -----
def func ( x):
  return 5* math.exp(-x)+x -5

# ---------- bisection method -- ----- ----- ---- -----
def bisection (a ,b) :

  if( func (a) * func (b) >= 0) :
    print (" you have not choose right a and b \n")
    return

  c = a ; # consider c is our root of equation
  while ((b -a) >= 0.00001) : # error [e *2^ n = (b-a)]
    c =( a+ b) /2
  # decide the side to repeat the steps
    if ( func ( c) ==0.0) :
      break
    if ( func ( c)* func (a) < 0) :
      b = c # [a, c]
    else : # [ func (c)* func (b) < 0 ]
      a = c # [c, b]

  print (" the value of root x is : ", c )
  wine_const = 1.4387752/(100 * c)
  print (" wine constant b : ", wine_const )


a = 0.0000001;
b = 10;
bisection (a , b)


Output:







Regula Falsi / False Position Method


# ---------- false Position Method -----------------

import numpy as np
import math

# ------------------ equation - ----- ----- ---- ----- --
def func ( x):
  return 5* math . exp (-x) + x - 5 # wien constant case
  
# ---------- false postion method - ----- ----- ---- ----

def false_postion (a , b , max_iter ):

  if ( func (a ) * func (b) >= 0) :
    print (" you have not choosen right range of a and b \n")
    return

  c = a # inital assume / result

  for i in range ( max_iter ) : #1
    c = ( a * func (b) - b * func (a ))/ ( func (b) - func (a ))
    # checking if the above point is over root or not
    if ( func ( c) == 0) :
      break # c is our root of equation
    elif ( func (c) * func ( a) < 0) :
      b = c # [a, c]
    else :
      a = c #[c, b]

  print (" the value of x is : ", c)
  wine_const = 1.4387752/(100 * c)
  print (" wine constant b : ", wine_const )
# -----------------------------------------

a = 0.0001
b = 10.0
max_iter = 50
false_postion (a , b , max_iter )
# --------------------------------------

Output:




Comments

Popular posts from this blog

Solving Kepler’s equation by Newton-Raphson method

Velapanti Python Program