I have a function that takes in either Float64
types or CValue
types (which is a custom type defined by me)
the function is of the form:
function _Ke(T,ρ,kf,r1,r2,r3)
Ke[r1] = _Ke_r1(T,ρ)*(1.0E-06)
kb[r1] = _kb_r1(kf[r1],Ke[r1],ρ)
Ke[r2] = _Ke_r2(T)*(1.0E-06)
kb[r2] = _kb_r2(kf[r2],Ke[r2],ρ)
Ke[r3] = _Ke_r3(T)*(1.0E-06)
kb[r3] = _kb_r3(kf[r3],Ke[r3],ρ)
return Ke, Kb
end
Where kf
is initialized by ones(Float64, Nr)
where Nr=3
in this instance.
I'm trying to set up the function so that it can output Ke
and kb
as a Float64 or CValue depending on the inputs to the function, but declaring:
Ke = Vector{CValue}(undef,Nr)
kf = Vector{CValue}(undef,Nr)
before calling this function seems to affect the function when I wish to only use values of Float64 not CValue.
Removing them yields the error: ERROR: LoadError: UndefVarError: Ke not defined
How do I amend my function so that it can seamlessly take in Float64 or CValue without explicitly referring to either in the function?
Ke
andKf
contain bothFloat64
andCValue
at the same time, or is it one or the other? And what do the output types depend on, do they depend on input values or input types? – DNFKe
andKf
but they do not appear in the arguments. If these are globals, then you should avoid that and instead put them in as the first argument and be explicit that you are going to change them (for which the Julia convention is to use a bang (!
) at the end of the function name). – Benoit Pasquierbkb
,bkf
,bKe
? They do not appear in your code example. – DNF