Example #1
0
 def setStatic(self):
         if self._mach_or_area  == 0:
                 pass
         elif self._mach_or_area == 1:
                 self.setStaticMach()
                 self.area =  self.W / ( self.rhos * self.Vflow )*144. 
         elif self._mach_or_area ==2:
                 Mach = .45
                 self.count = 0
                 maxIterCount = 100
                 def F1(Mach):
                         self.count = self.count + 1
                         self.Mach = Mach
                         self.setStaticMach( )
                         return  self.W / ( self.rhos * self.Vflow )*144. - self.area		
                 secant( F1, Mach+.05, Mach, MAXDX = .1, maxIter = maxIterCount )
                 if ( self.count > maxIterCount ):
                         self.Mach = 1
                         self.setStaticMach()
                         if ( self.W / ( self.rhos * self.Vflow )*144. > self.area ):
                                 print ("Error Choked Flow\n" )
                         else:
                                 print ( "Error in fixed area Mach number iteraion" )
         elif self._mach_or_area == 3:
                 self.setStaticPs()
Example #2
0
	        def F2(Pt):
	                def F1(Tt):
	                        self.setTotalTP( Tt, Pt )
	                        self.trigger = 1
	                        self.Mach = MN
	                        self.setStaticMach()
	                        return  self.Ts - Ts		
	                secant( F1, Tt+1, Tt, MAXDX = 100 )	
	                return self.Ps - Ps
Example #3
0
def pilihan(a, b, c, pil):
    if (pil == "1"):
        print("Metode Tabel")
        tabel(a, b, c)
    elif (pil == "2"):
        print("Metode biseksi")
        biseksi(a, b, c)
    elif (pil == "3"):
        print("Metode regula falsi")
        regula(a, b, c)
    elif (pil == "4"):
        print("Metode Newton Raphson")
        newton(a, b, c)
    elif (pil == "5"):
        print("Metode Secant")
        secant(a, b, c)
Example #4
0
    def setStatic(self):
        if self._mach_or_area == 0:
            pass
        elif self._mach_or_area == 1:
            self.setStaticMach()
            self.area = self.W / (self.rhos * self.Vflow) * 144.0
        elif self._mach_or_area == 2:
            Mach = 0.45

            def F1(Mach):
                self.Mach = Mach
                self.setStaticMach()
                return self.W / (self.rhos * self.Vflow) * 144.0 - self.area

            secant(F1, Mach + 0.05, Mach, MAXDX=0.1)
        elif self._mach_or_area == 3:
            self.setStaticPs()
Example #5
0
 def setStaticMach( self ):
         self.MachTemp = 0
         self.Ps = self.Pt*( 1 + ( self.gamt -1 )/2*self.Mach**2)**(self.gamt/( 1 - self.gamt ) )
         def eval(Ps):
                 self.Ps = Ps
                 self._flowS = self._flow
                 self._flowS.set(S=self.s/0.000238845896627,P=self.Ps*6894.75729)
                 self._flowS.equilibrate('SP' )
                 self.Ts = self._flowS.temperature()*9./5.
                 self.rhos = self._flowS.density()*.0624
                 self.gams = self._flowS.cp_mass()/self._flowS.cv_mass() 
                 self.hs = self._flowS.enthalpy_mass()*0.0004302099943161011 	          
                 Vson = math.sqrt(self.gams*GasConstant*self._flowS.temperature()/ self._flowS.meanMolecularWeight() )*3.28084
                 self.Vflow = math.sqrt(  778.169 * 32.1740 * 2 * ( self.ht - self.hs ) )
                 self.MachTemp = self.Vflow / Vson
                 return self.Mach - self.MachTemp
         secant(eval, self.Ps-.1, self.Ps)
Example #6
0
	def setStaticTsPsMN(self, Ts, Ps, MN ): 
	        self.trigger = 1 
	        Tt = Ts*(1+( self.gamt - 1 ) /2.* MN**2 )
	        Pt = Ps*( 1+( self.gamt - 1 ) /2.* MN**2 )**( self.gamt /( self.gamt -1 ))
	        self.setTotalTP( Tt, Pt )
	        self.trigger = 1
	        def F2(Pt):
	                def F1(Tt):
	                        self.setTotalTP( Tt, Pt )
	                        self.trigger = 1
	                        self.Mach = MN
	                        self.setStaticMach()
	                        return  self.Ts - Ts		
	                secant( F1, Tt+1, Tt, MAXDX = 100 )	
	                return self.Ps - Ps
	        secant( F2, Pt+.01, Pt, MAXDX = 10., TOL=1e-4 )	
	        self.area =  self.W / ( self.rhos * self.Vflow )*144. 
	        self.trigger = 0
Example #7
0
from newton_raphson import *
from secant import *

def f(x):
    return x**4 - 6.4*x**3 + 6.45*x**2 + 20.538*x - 31.752

def df(x):
    return 4.0*x**3 - 19.2*x**2 + 12.9*x + 20.538

x0 = 3.0
x1, _ = newton_raphson(f, df, x0, verbose=True, TOL=1e-12, multiplicity=2)

print("x1 = ", x1)
print("fx1 = ", f(x1))

x0 = 2.0
x2, _ = newton_raphson(f, df, x0, verbose=True, TOL=1e-12, multiplicity=2)

print("x2 = ", x2)
print("fx2 = ", f(x2))

print("diff = ", x2-x1)

x0 = 2.0
x3, _ = secant(f, x0, verbose=True, TOL=1e-12, multiplicity=2)

Example #8
0
from bisection import *
from newton import *
from secant import *

print("-------- START ---------")

print("Bisection")
f = "x*sin(x)-1"
a = 0
b = 2
tol = 0.001
print(bisection(f, a, b, tol))

print("\nNewton-Raphson")
f = "exp(-x)-x"
x0 = 0
tol = 0.0001
maxIter = 20
print(newton(f, x0, tol, maxIter))

print("\nSecant")
f = "x^3-3*x+2"
x0 = -2.6
x1 = -2.4
tol = 0.0001
maxIter = 20
print(secant(f, x0, x1, tol, maxIter))

print("-------- END ----------")
Example #9
0
def g(x):
    return (x * 2 + 10) / x / x


# ------------------------------------------------------------
# buscar raices
a, b = rootSearch(f, -10, 10, 0.5, printText=1)
# bisection
print "\nMetodo Bisection"
print bisection(f, a, b, switch=1)
# brent
print "\nMetodo Brent"
print brent(f, a, b, printText=0)
# secant
print "\nMetodo Secant"
print secant(f, a, b, printText=0)
# newton
print "\nMetodo de Newton"
print newton(f, d1f, a, printText=0)
# newton raphson
print "\nMetodo de Newton-Raphson"
print newtonRaphson(f, d1f, a, b, printText=0)
# posicion falsa
print "\nMetodo Posicion Falsa o Falsa Regla"
print falseRule(f, a, b, printText=0)
# punto fijo
print "\nMetodo Punto Fijo"
print fixedPoint(g, a, printText=0)
# steffensen
print "\nMetodo Steffensen"
print steffensen(g, a, printText=0)
Example #10
0
from bisection import *
from newtonraphson import *

if len(argv) != 2:
    print("Usage: ", str(argv[0]), "mode-number")
    print("1 : Bisection\n2 : Newton-Raphson\n3 : Secant")
    exit(1)


def fPrime(t, v=335.0, u=2510.0, M0=2.8 * 1e6, m=13.3 * 1e3, g=9.81):
    return float((u * m) / (M0 - m * t) - g)


def func(t, v=335.0, u=2510.0, M0=2.8 * 1e6, m=13.3 * 1e3, g=9.81):
    return float(u * log((M0) / (M0 - m * t)) - g * t - v)


mode = int(argv[1])

if (mode == 1):
    print("Using Bisection Method: ")
    print(bisection(func, 0, 200))
elif (mode == 2):
    print("Using Newton-Raphson Method: ")
    print(newtonraphson(func, fPrime, 60))
elif (mode == 3):
    print("Using Secant Method: ")
    print(secant(func, [0, 200], 10))
else:
    print("Undefined Mode NUmber")