0
|
12891 Views
|
|
0 Total Likes
View groups...
Share
GROUPS:

# Reusing variables in Widget Builder

Posted 9 years ago
 Hello, I want to use a variable in a formula multiple times without having to enter the same values more than once. For example, the effective half-life of radionuclide after ingestion is defined as: effectiveHalflife[physicalHalflife_, biologicalHalflife_] := (physicalHalflife * biologicalHalflife) / (physicalHalflife + biologicalHalflife)  The residual mass after some elapsed time then would be: residualMass[n0_, time_, physicalHalflife_, biologicalHalflife_] := n0 * 0.5^(time/effectiveHalflife[physicalHalflife, biologicalHalflife])  I now want to build a widget of this formula, but I can't find out how to reuse physical- and biological halflife without having to enter these twice. Say I already have this template: [//quantity:${ingestedMass}//] * 0.5^ ([//quantity:${elapsedTime}//] / ([//quantity:${phyHl}//] * [//quantity:${bioHl}//] / ([//quantity:${phyHl}//] + [//quantity:${bioHl}//]) ) )  How would reuse phyHl and bioHl without having to enter these values twice? Thanks, Alex.
 Hey Alex,This might be a tad late, but you can reuse variables by defining them at the end of the query: [//quantity:${ingestedMass}//] * 0.5 ^ ([//quantity:${elapsedTime}//] / (p * b / (p + b))), where p = [//quantity:${phyHI}//], b = [//quantity:${bioHI}//] Edit: Alternatively, you can use the ReplaceAll[expr, rules] function: [//quantity:${ingestedMass}//] * 0.5 ^ ([//quantity:${elapsedTime}//] / ReplaceAll[p * b / (p + b)), {p->[//quantity:${phyHI}//], b->[//quantity:${bioHI}//]}] ~a different Alex