i have calculate following function:
f(x)=x^3-x-1
i've created class, named "function" , inside of it, have method calculating above function.
here comes code:
double function(double num) { bigdecimal first,second; double a,b,c,b_copy; = math.pow(num, 3); b=(double)a-num; first=new bigdecimal(b); second=new bigdecimal("1.0"); first.min(second); b_copy=first.doublevalue(); return b_copy ; }
i have problems these 2 lines of code:
first.min(second); b_copy=first.doublevalue();
for example when num
0 b_copy
must -1 0. why that?
the min(...)
method returns bigdecimal
, doesn't modify it. try this:
first = first.min(second);
also, if want subtract 1
value of first
(as formula indicates), use subtract(...)
method because min(...)
returns smallest values of 2 bigdecimal
s.
first = first.subtract(second);
Comments
Post a Comment