Link to home
Start Free TrialLog in
Avatar of Chrysaor
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
Avatar of tculler
tculler
Flag of United States of America image

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.
Avatar of Chrysaor
Chrysaor

ASKER

Excactly as jhshukla said.. Any ideas?
SOLUTION
Avatar of MatrixDud
MatrixDud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

/* 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;
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial