Hello I would like to know how to implement the "ln" function in the math.h libary. I would like to implement the equation ln(a^2-d/2a) I would appriciate any help that anyone give me.
Printable View
Hello I would like to know how to implement the "ln" function in the math.h libary. I would like to implement the equation ln(a^2-d/2a) I would appriciate any help that anyone give me.
?Code:double foo(double a, double d)
{
return log(exp(a * a) - d / (2 * a));
}
Hello thanks for that but i'am still having problems implementing it. I want to implement the equation ln((8*L-1)/D) the code below is what i have that is not working
Code:
b=log(exp((8*L)-1/ D));
Learn about the change of base rule
Quick tip: ((8*L-1)/D), as stated in your question, is not the same as ((8*L)-1/ D)
which is in your code.
Another quick tip: stick to one equation, as you have now posted 3 different
equations.
All you need to know is basic math to figure out this one. * before / before + before -
Thus, if you removed all of the parenthesis, and just relied on basic math properties, you would get:
A = 8 * L resolved first.
B = 1 / D resolved next.
C = A - B resolved last.
This is why we have the phrase, "When in doubt, use lots of parenthesis!" Or something to that effect.
Quzah.
Studying an operator precedence table might help: http://www.isthe.com/chongo/tech/com...recedence.html
I corrected my mistake but the problem now is that the ln function which I wrote as log(exp) is not giving me a proper value I checked it
b=log(exp((8*L-1)/D));
if L=3
D=7
the answer is meant to be 1.189584 but instead it 3.285714
I will be very greatful if someone can help me.
Do I have to do everything for you? I already posted a link for you to look
at the change of base rule. By applying that, using log () - which is base 10,
to get a result in ln you do this:
Now go away.Code:#include <stdio.h>
#include <math.h>
int main (void)
{
double b, L = 3, D = 7;
b=(log((8*L-1)/D))/(log (exp (1.0)));
printf ("b is %f", b);
return 0;
}
Hmm?Quote:
Originally Posted by Richie T
Quote:
The log functions compute the base-e (natural) logarithm of x.
Quote:
The log10 functions compute the base-10 (common) logarithm of x.
Oops! My mistake, should have looked that up before I submitted, nonetheless
the code I posted gives the right answer since it ends up dividing by 1!