julia函数定义与调用示例代码

代码语言:julia

所属分类:其他

代码描述:julia函数定义与调用示例代码

代码标签: 调用 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

# function to calculate the volume of a sphere
function sphere_vol(r)
    # julia allows Unicode names (in UTF-8 encoding)
    # so either "pi" or the symbol π can be used
    return 4/3*pi*r^3
end

# functions can also be defined more succinctly
quadratic(a, sqr_term, b) = (-b + sqr_term) / 2a

# calculates x for 0 = a*x^2+b*x+c, arguments types can be defined in function definitions
function quadratic2(a::Float64, b::Float64, c::Float64)
    # unlike other languages 2a is equivalent to 2*a
    # a^2 is used instead of a**2 or pow(a,2)
    sqr_term = sqrt(b^2-4a*c)
 .........完整代码请登录后点击上方下载按钮下载查看

网友评论0