Ejemplo n.º 1
0
// calculates transformation matrix for a single cone of an instrument's profile
func stageMatrix2(radiusIn, radiusOut, radiusCenter, length, radianFrequency float64) [4]complex128 {
	xi := complex(radiusIn, 0)   // m
	xi1 := complex(radiusOut, 0) // m
	l := complex(length, 0)      // m
	w := radianFrequency         // rad / s

	centerPlaneArea := pi * radiusCenter * radiusCenter // m2
	sm := centerPlaneArea

	sphericalAreaIn := 4 * pi * radiusIn * radiusIn // m2
	si := sphericalAreaIn

	rv := math.Sqrt(p * w * sm / (n * pi)) // rad^1/2
	r0 := p * c / si                       // kg/(m4*s) or Pa*s, units of impedance
	k := w / c                             // wavenumber, rad / m

	zc := complex(r0, 0) * complex(1+0.369/rv, -0.369/rv) // Pa*s/sqrt(rad)
	g := complex(k, 0) * complex(1.045/rv, 1+1.045/rv)    // sqrt(rad)/m

	gl := g * l                                                                 // sqrt(rad)
	cosh_gl := cmplx.Cosh(gl)                                                   // mangled sqrt(rad)
	sinh_gl := cmplx.Sinh(gl)                                                   // mangled sqrt(rad)
	a11 := xi1 / xi * (cosh_gl - sinh_gl/(g*xi1))                               // unitless (more mangled sqrt(rad))
	a12 := xi / xi1 * zc * sinh_gl                                              // Pa*s + mangle
	a21 := 1 / zc * ((xi1/xi-1/(g*g*xi*xi))*sinh_gl + (gl*cosh_gl)/(g*g*xi*xi)) // 1/(Pa*s) + mangle
	a22 := xi / xi1 * (cosh_gl + sinh_gl/(g*xi))                                // unitless + mangle

	return [4]complex128{a11, a12, a21, a22}
}
Ejemplo n.º 2
0
	"strconv"
	"sync"
	"time"
)

type ComplexFunc func(complex128) complex128

var Funcs []ComplexFunc = []ComplexFunc{
	func(z complex128) complex128 { return z*z - 0.61803398875 },
	func(z complex128) complex128 { return z*z + complex(0, 1) },
	func(z complex128) complex128 { return z*z + complex(-0.835, -0.2321) },
	func(z complex128) complex128 { return z*z + complex(0.45, 0.1428) },
	func(z complex128) complex128 { return z*z*z + 0.400 },
	func(z complex128) complex128 { return cmplx.Exp(z*z*z) - 0.621 },
	func(z complex128) complex128 { return (z*z+z)/cmplx.Log(z) + complex(0.268, 0.060) },
	func(z complex128) complex128 { return cmplx.Sqrt(cmplx.Sinh(z*z)) + complex(0.065, 0.122) },
}

func RunJulia() {
	t := time.Now()
	for n, fn := range Funcs {
		err := CreatePng("picture-"+strconv.Itoa(n)+".png", fn, 1024)

		if err != nil {
			log.Fatal(err)
		}
	}
	fmt.Println("Time passed: ", time.Since(t).Seconds())
}

// CreatePng creates a PNG picture file with a Julia image of size n x n.
Ejemplo n.º 3
0
type ComplexFunc func(complex128) complex128

var Funcs []ComplexFunc = []ComplexFunc{
	func(z complex128) complex128 { return z*z - 0.61803398875 },
	func(z complex128) complex128 { return z*z + complex(0, 1) },
	func(z complex128) complex128 { return z*z + complex(-0.835, -0.2321) },
	func(z complex128) complex128 { return z*z + complex(0.45, 0.1428) },
	func(z complex128) complex128 { return z*z*z + 0.400 },
	func(z complex128) complex128 { return cmplx.Exp(z*z*z) - 0.621 },
	func(z complex128) complex128 {
		return (z*z+z)/cmplx.Log(z) + complex(0.268,
			0.060)
	},
	func(z complex128) complex128 {
		return cmplx.Sqrt(cmplx.Sinh(z*z)) +
			complex(0.065, 0.122)
	},
}

//This makes the program use all the cores in the processor
func init() {
	numcpu := runtime.NumCPU()
	runtime.GOMAXPROCS(numcpu) // Try to use all available CPUs.
}

func main() {
	wg := new(sync.WaitGroup)
	before := time.Now()
	for n, fn := range Funcs {
		wg.Add(1)
func test1(val, val0 complex128) complex128 {
	return cmplx.Sqrt(cmplx.Sinh(val)) + val0
}