>I have been working on this C++ project forever and I can't seem to get it.
You have...
http://www.daniweb.com/techtalkforums/thread40264.html
I'm glad to see you ditched the newton/raphson method for an algorithm where you don't have to test your own calculus skills.
However, in order to make this more readable use code tags to properly indent your code.
x(1 + [summation from 1 to M of (Kj*Nj)/(1 + Kj*x)]) - L = 0
[tex]x(1+\sum_{j=1}^{M} \frac{k_j*N_j}{1+K_j*x})-L=0[/tex]
Is dat what you mean it to look like?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Sorry,on second thought, the summation function has confused me. I've never worked with root finding algorithms that contain summation thingies. :sad:
Moreover, the example you have given perplexes me further:
i.e. I would input M=2, K1=1, N1=1, K2=2, N2=.5, L=3, etc. I would be soooo appreciative of any help! Thanks!
That is telling me that 'k' increments by one and 'n' decrements by 0.5 at each step. Is that right?
I've only used root finding methods with plain old functions [tex]y=(x-2)(x+3)[/tex].
Second I don't necessarily get why it has changed since your last post. You didn't have a summation thing in there before so where did it creep in?
Third, have you plotted the graph so you can see where the roots are...so you know what values you can choose for [tex]a[/tex] and [tex]b[/tex].
I don't no, maybe someone with more experience can help you.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Well I took a look at your problem. Regarding the bisection-method looks as if you dont have an idea with what you are doing. I will give you a brief algorithm here and try to see if you can understand it and implement it.
Eq is
x[ 1 + k1*n1/(1 + k1*x ) + k2*n2/(1 + k2*x ) + ... km*nm/(1 + km*x ) - L = 0
The idea of the bisectional method is to first find two values of x so that the left part of the above equation is positive for one of those values and negative for the other value.
If you take x = 0 as one of the values, by substituting x = 0 to the above equation, the left side will be equal to -L.
So now we have to find another value of x such that the left part of the equation is of opposite sign of -L.
To do this
for ( x = 1 ; x < INT_MAX; x++ )
{
value = x[ 1 + k1*n1/(1 + k1*x ) + k2*n2/(1 + k2*x ) + ... km*nm/(1 + km*x ) - L ;
if ( ( (-L ) > 0 and value < 0 ) or ( ( (-L ) < 0 and value > 0 ) )
{
secondvalue = x ;
break;
}
// Maybe -x has a value where the sign changes
value = (-x)[ 1 + k1*n1/(1 + k1*(-x) ) + k2*n2/(1 + k2*(-x) ) + ... km*nm/(1 + km*(-x) ) - L ;
if ( ( (-L ) > 0 and value < 0 ) or ( ( (-L ) < 0 and value > 0 ) )
{
secondvalue = (-x) ;
break;
}
}
if ( x == INT_MAX )
{
no value found where the LHS changes signs.
This means that the function hasnt got roots. at least under the INT_MAX limit.
return from the function.
}
you are here means that you have got a valid value for secondvalue also.
For the rest of the part you can refer this URL. Bisection Simulation .
Just remember that the first positiveguess and negativeguess pair is the one we found above, i.e 0 and secondvalue.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Sure what have you got so far?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439