We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,668 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Java Decimals

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

4
Contributors
9
Replies
4 Months
Discussion Span
2 Years Ago
Last Updated
10
Views
deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

masijade
Industrious Poster
Team Colleague
4,253 posts since Feb 2006
Reputation Points: 1,484
Solved Threads: 494
Skill Endorsements: 17

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???

deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Sorry, this is not a math site, though.

masijade
Industrious Poster
Team Colleague
4,253 posts since Feb 2006
Reputation Points: 1,484
Solved Threads: 494
Skill Endorsements: 17

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!

jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
Skill Endorsements: 4

:(
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

deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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. ;)

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 376
Skill Endorsements: 17

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

deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 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.

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 376
Skill Endorsements: 17

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.:)

deviliq
Light Poster
26 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0865 seconds using 2.75MB