Ferguson Ferguson - 2 months ago 20
C Question

Convert math expression into C or Java code

I need to rewrite this expression into code (C or Java):

g
,
h
,
i
,
j
,
f
,
f0
are variables

Expression:

val = 1/{g+h[ln(f0/f)]+i[ln^2(f0/f)]+j[ln^3(f0/f)]-273.15;


The problem I have is converting
ln^2(f0/f)
into code.

Is this
(pow(ln(fo/f),2))
and
ln^3(f0/f)
is
pow(ln(f0/f),3)
?

Thank you.

Answer

In java, ln^n(f0/f) would be: Math.pow(Math.log(f0/f), n)