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.
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)); }
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
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.
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI
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.
Hope is the first step on the road to disappointment.
Studying an operator precedence table might help: http://www.isthe.com/chongo/tech/com...recedence.html
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
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; }
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI
Hmm?Originally Posted by Richie TThe log functions compute the base-e (natural) logarithm of x.The log10 functions compute the base-10 (common) logarithm of x.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
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!
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI