Simple math equation??

Pages: 12
Can't seem to figure out why I get '-17172.5' as an answer for 'dq' when the correct answer should be '5283.212' Can anyone spot an easy error I may have missed I've been staring at it for hours cheers


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cmath>

using namespace std;

int main()

{ 
    float a = .05;
    float y = .05;
    float dq;
    float f = 3.0;
    float k = .1;
    
    
    dq = (15072*(1-(((a + y)/a)/(1+(((a + y)*f)/(k*(log((a + y))/a)))))));


cout<<dq<<"\n";

system("Pause");
}
Your code is the example of when excess parentheses make a code difficult to read. For example why are there th second pair of parentheses?!

log((a + y))

Remove excess parentheses and post your code anew.
this is an impossible task for us.
here you have a wrong equation that is eaqual to -17172.5.
try to alter it so it becomes 5283.212. it's just impossible to do that.
maybe try to tell us what exactly you are calculating when u get the value of dq? or how did you get that equation.
if i calculate it myself i also get-17172.5
Last edited on
I cut out some sets of parenthesis and got a number closer to the actual answer but I am still tweaking it

Maybe it would help if I posted my written math equation (below) that I am trying to type in c++

dq = 15072*[1 – {(a+y/a)/(1 + ((a+y*F)/k*log(a+y/a)))}]
Last edited on
found it :
vlad said it without noticing
dq = (15072*(1-(((a + y)/a)/(1+(((a + y)*f)/(k*(log((a + y))/a)))))));
should be this:
 
dq = 15072*(1-(((a + y)/a)/(1+(((a + y)*f)/(k*(log((a + y)/a)))))));
Last edited on
if i calculate this i get that dq=12323.08581
dq = 15072*[1 – {(a+y/a)/(1 + ((a+y*F)/k*log(a+y/a)))}]
as do i gelatine, it just doesnt make sense

unless....... my answer key is wrong
if this is what your equation is then the solution is really 12323.08581 and the solution key is wrong.
i have a program on my calculator that solves any equation and it also resulted in that
unless you gave us wrong values for the variables :s
Last edited on
could you use that program and calculate the equation again but instead of using natural log use just common log (log(base10)) and see what answer you get?
i don't exactly get what you mean but
i have entered dq = 15072*[1 – {(a+y/a)/(1 + ((a+y*F)/k*log(log(a+y/a))))}]
now and the answer is 21412.968
My result is 653.374

1
2
3
4
5
6
7
8
9
10
11
12
double a = .05;
double y = .05;
double dq;
double f = 3.0;
double k = .1;
    
    
dq = 15072 * 
 ( 1.0 - ( a + y / a ) / ( 1.0 + ( a + y * f ) / k * std::log( a + y /a ) ) ); 


std::cout << dq << "\n";


Who will suggest greater?:)
Last edited on
your fault is that you use ( a + y /a ) which is 0.05+ (0.05/0.05)
and it should be ( 0.05+ 0.05)/0.05
Last edited on
ok i my calculater uses base 10. so i believe it should be base 2 but i don't know how to change it on my calculator. i'm trying to find that now
Here the order of the calculations is very important. After I have inserted an additional pair of parentheses around

( k * std::log( a + y /a ) )

I get result

14695.1

that may be it, i get different dq answers when i use 'log' as opposed to 'log10' in c++
or like vlad said maybe i could just be missing or have a set of parenthesis in the wrong spot
Also if substitute a + y /a for ( a + y )/a then my result is

7313.71
Last edited on
keep it coming you are getting closer to 5283.212!
so use log(( a + y )/a)/log(2) and then you have base 2 log of ( a + y )/a
now i have 7536 by using this
dq = 15072*(1-(((a + y)/a)/(1+(((a + y)*f)/(k*(log((a + y)/a)/log(2.0)))))));
EDIT love this: free post count ;p
Last edited on
Pages: 12