Chrysaor
asked on
Solving exponential equations in C++
Is there a function or a library that can solve equations like: exp(constant*x) + exp(constant*x) = constant ?
If not , what is the best way to solve this equation in c++ ?
Thanks
If not , what is the best way to solve this equation in c++ ?
Thanks
Depends on what you mean by "exp"--what is this function supposed to do? Also, you can't assign a constant to anything but a constant, as far as I know. The entire expression must be a constant (unless x is a constant as well). Can you be a bit more specific as to what exactly you're trying to accomplish?
He is trying to solve the equation "e^mx + e^nx = k" for x; m, n & k are known.
ASKER
Excactly as jhshukla said.. Any ideas?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
/* Newton's method example.
http://en.wikipedia.org/wiki/Newton%27s_method */
#include <stdio.h>
#include <math.h>
/* the function */
#define f(x) exp(2*x)+exp(3*x)-5
/* the derivative on x */
#define f_(x) 2*exp(2*x)+3*exp(3*x)
/* the first quess */
#define x0 -1
/* precision */
#define epsilon 1e-9
int main()
{
double prev,curr,delta;
prev=curr=x0;
while(1)
{
curr = prev - (f(prev)/f_(prev));
delta = fabs(curr-prev);
printf(">> %.10f e=%.10f\n",curr,delta);
if (delta < epsilon)
break;
prev = curr;
}
printf("%.10f\n",curr);
return 0;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.