calculating the area of a circle with bc

Tony Arnold tony.arnold at manchester.ac.uk
Sun Mar 28 19:41:39 UTC 2010


Colin,

Colin Law wrote:
> On 28 March 2010 20:24, Tony Arnold <tony.arnold at manchester.ac.uk> wrote:
>> Jozsef,
>>
>> Since the area of a pizza is directly proportional to its diameter, you
>> only really need to calculate the price/diameter to find out the best
>> value for money!
> 
> It is proportional to the square of the diameter

Oops! My bad. But the price/diameter is still good enough to determine
the best value for money!

>>> echo "$2/$(echo "scale=100; 2^($1/2) * $(echo "scale=100; 4*a(1)" | bc
>>> -l)" | bc -l)" | bc -l
>>>
>>>
>>> is there a shorter/better way?

Why so many nested echo etc? Why not give bc the full expression? I
think you also mean ($1/2)^2 instead of 2^($1/2). So you get

echo "scale=100;$2/(($1/2)^2*4*a(1))" | bc -l

Regards,
Tony.
-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 870 136 1004
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: tony.arnold at manchester.ac.uk




More information about the ubuntu-users mailing list