I have a problem calculating with significant figures in Wolfram Mathematica. Let me explain better.
I have
f[a_, b_] = a b Sin[25]
and
f[92.0 , 9.81] =381.421
However, I would first like to approximate the result of the product between a and b to three significant digits and then multiply it by Sin [25]. In short, I would like a function like this
f1[a_, b_] = NumberForm[a b, {3, 0}] Sin[25]
But if I evaluate
f1[92,0 , 9.81]
I get
f1[92,0 , 9.81]= 903.Sin[25]
instead of 381.62.
How should I modify f1[a_, b_] to get f1[92,0 , 9.81]=381.62 ?
You can use
Roundto round to 3 significant digits in your specific case. Then the result is an integer, soSin[25]does not convert to a real number (a floating point number). However this can be forced withN.Also
Sinassumes radian input unless the input is specified as degree.Note use of
SetDelayed(:=) for the function definition.For 3 significant digits on
a bin general you can useE.g. rounding
a b