1,105,556 Community Members

Java Decimals

Member Avatar
deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
-1
 

Hello there! :)

How should i solve for x in this equation:
p*e^-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x^2 + u = 0
with the user to input the values of p,q,r,s,t and u.

i'm thinking of looping from 0.0001 until i-dont-know-what
and then testing each value of x that will satisfy the equation.
but i dont think that's very efficient... especially if the given p,q,r,s,t and u values would yield to no possible value of x...

Post for this prob is right here:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1282

Member Avatar
masijade
Industrious Poster
4,165 posts since Feb 2006
Reputation Points: 1,351 [?]
Q&As Helped to Solve: 510 [?]
Skill Endorsements: 22 [?]
Team Colleague
Featured
 
0
 

First of, use your algebra skills to "turn the equation around" until you have an x= .... equation. Then the rest should be self-explanatory.

Member Avatar
deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

yup that was the veryyyy first thing i thought of,
but then... it was actually.... errrrrrr

p*e^-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x^2 + u = 0
p*e^-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x^2 = -u

there, i was STUCK... T___T
logarithm, arcsin, arccos, arctan, square root???

Member Avatar
masijade
Industrious Poster
4,165 posts since Feb 2006
Reputation Points: 1,351 [?]
Q&As Helped to Solve: 510 [?]
Skill Endorsements: 22 [?]
Team Colleague
Featured
 
0
 

Sorry, this is not a math site, though.

Member Avatar
jon.kiparsky
Posting Virtuoso
1,837 posts since Jun 2010
Reputation Points: 326 [?]
Q&As Helped to Solve: 192 [?]
Skill Endorsements: 6 [?]
 
0
 

Nor, we might point out, is it a site which is in the business of giving away contest answers. It's extremely poor form to cheat, which is what you're trying to do. It's extremely stupid to announce that you're entering a java contest and then ask for help giving the contest web site as the URL for the problem you're trying to solve. Kind of gives the game away.

Unless there's something in the rules specifically allowing outside help, this is very bad, and speaks very poorly for you. Please act in a responsible manner in the future - and I don't mean by covering your tracks better!

Member Avatar
deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

:(
hey hey
where did i ever mention that this was part of the contest i was joining? The contest was offline. The problems were on paper. All we had to do was to code in JCreator LE.
the site where i got this problem from was an online repository of different programming problems. i googled it myself so that I may have an idea of what sort of problems may come out.
how's that for cheating? and is this not acting in a responsible manner?
geesh
anyways i won 2nd with 6 probs over 8 in the 3 hour limit and thankfully this prob didnt come out. :P

Member Avatar
Taywin
Posting Maven
2,632 posts since Apr 2010
Reputation Points: 134 [?]
Q&As Helped to Solve: 378 [?]
Skill Endorsements: 17 [?]
 
0
 

Well, good for you. Still, you aren't using the forum the way it should. This is Java forum which is for those who have problems with how to code, not how to solve a problem from words to code.

One thing about your equation, the solution is not a simple algebra by the way. You need to apply some trigonometry to it, but it is solvable. ;)

Member Avatar
deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hmm, if i remember the reason for posting this...
it was a problem i had with java decimals
i tried to loop from
0.0001 until 1 since this is the range for x
i then iterated x by 0.0001
but the problem i had was that the operation result turned out to be something like:
x = 0.0001 + 0.0001 = 0.00019
it wasnt accurate... x.x
its as far as i cud remember

Member Avatar
Taywin
Posting Maven
2,632 posts since Apr 2010
Reputation Points: 134 [?]
Q&As Helped to Solve: 378 [?]
Skill Endorsements: 17 [?]
 
0
 

The problem is always there. It is the different of float/double that a computer cannot exactly represent but only estimate it. It could be the inaccurate of the epsilon.

Member Avatar
deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hey there :)
i found the perfect answer for my query :)

float

and

double

are actually pretty accurate ESTIMATES. Thus, both are widely used in scientific calculations of very very large or very very small numbers...
in cases where data is sensitive and has to be accurate (like money, for example)
it is best to use

int

(then keep track of the decimal point),

long

, or

BigDecimal

instead. of course, this is in java only.:)

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: