How to pass parameter list to a function in Julia

后端 未结 5 707
名媛妹妹
名媛妹妹 2021-01-25 07:27

I am newbie in Julia language, and the tutorial is not very deep yet and I didn\'t understand what is the best way to pass a parameter list of a function. My function looks like

5条回答
  •  面向向阳花
    2021-01-25 07:44

    You may use the power of functional language (function as a first-class object and closures):

    julia> compose_dxdt = (a,b,c) -> (x) -> a*x^2 + b*x + c #creates function with 3 parameters (a,b,c) which returns the function of x
    (anonymous function)
    
    julia> f1 = compose_dxdt(1,1,1) #f1 is a function with the associated values of a=1, b=1, c=1
    (anonymous function)
    
    julia> f1(1) 
    3
    
    julia> f1(2)
    7
    
    julia> f2 = compose_dxdt(2,2,2) #f1 is a function with the associated values of a=2, b=2, c=2
    (anonymous function)
    
    julia> f2(1)
    6
    
    julia> f2(2)
    14
    

提交回复
热议问题