Go is an open source programming language. It is usually called modern C language. I think it is suitable for scientific computation in electromagnetic because it is support the complex number computation. So I tried to use it to solve a complex ordinary differential equations.
Development Environment
VScode is a free and popular development IDE for go language. The main steps to configuration are:
- Download VScode from https://code.visualstudio.com/ and install it
- Install the go extension in VScode
- Download Go lang from golang.org and install it
- Install the debugger for go by running: go get github.com/go-delve/delve/cmd/dlv in console
- Create an empty file with .go extension and open it in vscode
- Run the command: go mod init lubo.ml/hello
- Create launch.js in vscode
{
"version": "0.2.0",
"configurations": [
{
"name": "golang",
"type": "go",
"request": "launch",
"mode": "debug",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceFolder}",
"env": {
},
"args": []
}
]
}
Then the environment is installed. The program can be debugged in vscode and enjoy.
How to deal with complex number?
A float32 provides approximately six decimal digits of precision, whereas a float64 provides about 15 digits; float64 should be preferred for most scientific computation. Go provides two sizes of complex numbers, complex64 and complex128, whose components are float32 and float64 respectively. The build-in function function complex creates a complex number from its real and imaginary components. If both the real and imaginary parts is float64, then it return a complex 128.
One idea to deal with complex number is treat all the number as complex128, which Matlab do. Then the + – * and / operator work well. The operation between a constant real number and a complex128 variable is also allowed. However the operation between a variable or constant in real value and a complex128 is not allowed.
For example
a:=complex(1.0,1.0)
b:=5.0
c:=a+5 //OK 6+i
c:=a*5 //OK 5+5i
c:=a+b //go build failed.
Summery
Go is suitable for scientific computation. It can handle complex numbers.