Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Syntax Highlighting in LaTeX with the listings Package

writeLaTeX
June 1, 2018

1 VHDL

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− T i t l e : SAD
−− P r o j e c t : F i n a l p r o j e c t : SAD C a l c u l a t i o n
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− F i l e : SAD. vhd
−− Language : VHDL
−− Author ( s ) : F r a n c e s c o Urbani
−− Company :
−− Created : F r i May 18 1 6 : 2 3 : 3 3 CEST 2018
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− D e s c r i p t i o n : Actual SAD c a l c u l a t o r ( top l e v e l )
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
−− Update :
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

library ieee ;
use i e e e . s t d l o g i c 1 1 6 4 . a l l ;
−− u s e i e e e . s t d l o g i c u n s i g n e d . a l l ;
use i e e e . numeric std . a l l ;

2 Java
c l a s s HelloWorldApp {
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) {
System . out . p r i n t l n ( ” H e l l o World ! ” ) ; // D i s p l a y t h e s t r i n g .
f o r ( i n t i = 0 ; i < 1 0 0 ; ++i ) {
System . out . p r i n t l n ( i ) ;
}
}
}

3 Python

1
#! / u s r / l o c a l / b i n / python
# c o d i n g : l a t i n −1

from math import atan2 , p i


from f r a c t i o n s import F r a c t i o n
from d e c i m a l import Decimal

#Function used t o p r i n t h e numbers .


#i f t h e number doesn ’ t s t o p u n t i l t h e 15 th decimal , i t i s p r i n d e t e n t i r e l y .
d e f myFormat ( x ) :
r e t u r n ( ’ %.10 f ’ % x ) . r s t r i p ( ’ 0 ’ ) . r s t r i p ( ’ . ’ )

#module o f t h e complex number x+j y


d e f module ( x , y ) :
r e t u r n ( x ∗∗2 + y ∗ ∗ 2 ) ∗ ∗ 0 . 5

#phase o f t h e complex number x+j y


d e f phase ( x , y ) :
r e t u r n atan2 ( y , x )

d e f t h i r d g r a d e e q u a t i o n ( c3 , c2 , c1 , c0 ) :
p r i n t ” Third g r a d e e q u a t i o n ”
p r i n t ” S t i l l working on t h i s f e a t u r e . . . ”

def second grade equation (a , b , c ) :


d e l t a = ( b∗∗2 − 4∗ a ∗ c )
i f d e l t a >0:
p r i n t ( ” Second g r a d e e q u a t i o n . 2 r e a l r o o t s ” )
p r i n t ( ” d e l t a = %s ” ) % myFormat ( d e l t a )
p r i n t ( ” x1 = %s ” ) %myFormat((−b + d e l t a ∗ ∗ 0 . 5 ) / ( 2 ∗ a ) )
p r i n t ( ” x2 = %s ” ) %myFormat((−b − d e l t a ∗ ∗ 0 . 5 ) / ( 2 ∗ a ) )
e l i f d e l t a == 0 :
p r i n t ( ” Second g r a d e e q u a t i o n . 2 c o i n c i d e n t r o o t s ” )
p r i n t ( ” d e l t a = %s ” ) %myFormat ( d e l t a )
p r i n t ( ” x1 = x2 = %s ” ) % myFormat ( b / ( 2 ∗ a ) )
else : #
complex
d e l t a = −d e l t a
r e = f l o a t (−b ) / ( 2 ∗ a ) #r e a l p a r t
im = ( d e l t a ∗ ∗ 0 . 5 ) / ( 2 ∗ a ) #i m a g i n a r y p a r t
i f r e != 0 :
p r i n t ( ” Second g r a d e e q u a t i o n . 2 complex r o o t s ” )
p r i n t ( ” d e l t a = %s ” ) %myFormat(− d e l t a )
p r i n t ( ” x1 = %s + j%s ” ) %( myFormat ( r e ) , myFormat ( im )
)
p r i n t ( ” x2 = %s − j%s ” ) %( myFormat ( r e ) , myFormat ( im )
)
p r i n t ( ” \n” )
p r i n t ( ” x1 = %sexp ( j%s ) ” ) % ( myFormat ( module ( re , im ) )
, myFormat ( phase ( re , im ) ) )
p r i n t ( ” x2 = %sexp (− j%s ) ” ) % ( myFormat ( module ( re , im ) )

2
, myFormat ( phase ( re , im ) ) )
else :
p r i n t ( ” Second g r a d e e q u a t i o n . 2 pure i m a g i n a r y r o o t s ”
)
p r i n t ( ” d e l t a = %s ” ) %myFormat(− d e l t a )
p r i n t ( ” x1 = j%s ” ) %myFormat ( im )
p r i n t ( ” x2 = −j%s ” ) %myFormat ( im )
p r i n t ( ” \n” )
p r i n t ( ” x1 = %sexp ( j p i / 2 ) ” ) %myFormat ( im )
p r i n t ( ” x2 = %sexp (− j p i / 2 ) ” ) %myFormat ( im )
def f i r s t g r a d e e q u a t i o n (b , c ) :
i f b == 0 :
i f c == 0 :
p r i n t ”0 = 0 . I ’ l l take note . ”
else :
p r i n t ” O p e r a t i o n f a i l e d . %s i s not e q u a l t o 0 ” %
myFormat ( c )
else :
p r i n t ( ” F i r s t grade equation . 1 root ” )
p r i n t ( ”x = %s ” ) %myFormat ( f l o a t (−c ) /b )

d e f c a l c u l a t e ( c3 , c2 , c1 , c0 ) :
i f c3 == 0 :
i f c2 == 0 :
f i r s t g r a d e e q u a t i o n ( c1 , c0 )
else :
s e c o n d g r a d e e q u a t i o n ( c2 , c1 , c0 )
else :
t h i r d g r a d e e q u a t i o n ( c3 , c2 , c1 , c0 )

p r i n t ’ Type 2nd , 1 s t and 0 th c o e f f . i n t h i s o r d e r ’


c2 , c1 , c0 = map( f l o a t , r a w i n p u t ( ) . s p l i t ( ) )

c a l c u l a t e ( 0 , c2 , c1 , c0 ) #c3 = 0 . . . change t o implement 3 rd g r a d e e q u a t i o n

# print Fraction (0.6666666) . limit denominator ()

4 MATLAB/Octave
o c t a v e :1> f u n c t i o n xdot = f ( x , t )
>
> r = 0.25; k = 1.4;
> a = 1.5; b = 0.16; c = 0.9; d = 0.8;
>
> xdot ( 1 ) = r ∗x ( 1 ) ∗ ( 1 − x ( 1 ) /k ) − a∗x ( 1 ) ∗x ( 2 ) / ( 1 + b∗x ( 1 ) ) ;
> xdot ( 2 ) = c ∗ a∗x ( 1 ) ∗x ( 2 ) / ( 1 + b∗x ( 1 ) ) − d∗x ( 2 ) ;
>
> endfunction

You might also like