• Post Reply Bookmark Topic Watch Topic
  • New Topic

To calculate 9th root of any number without using build in function  RSS feed

 
Gursewak Singh
Ranch Hand
Posts: 79
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to calculate 9th root of a number without using any build in functions.
it can be in c,c++, or java.
so kindly suggest me
Logarithm is a good option, but how to calculate Anti log
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to look up some algorithms. I think their expansions are called Taylor series. There are examples for sin, cos, log and exponentials, etc. I had to know them at school when I did maths. Once you know the algorithm, you can easily implement ln(x) and exp(x) as doubles. It’s quite easy.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though if I wasn't allowed to use any library methods at all, I'd be tempted to solve this with a Newton-Raphson method or similar (look for solutions of x^9 - a = 0).
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you going to do much of anything without built-in functions? How will you get input? How will you print results to the screen?
 
Gursewak Singh
Ranch Hand
Posts: 79
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred mean to say, i don't want to use math functions for that
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean, other than +, - *, /? It's going to be hard (impossible) to do this without some built-in math functions. Let's be specific about exactly what you're allowed to use.

And like Matthew, I'd look into using Newton's method. Have you had calculus? Do you understand how derivatives work, and what they mean?

 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had forgotten about Newton’s approximation.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gursewak Singh wrote:Fred mean to say, i don't want to use math functions for that

I know what you meant...sort of.

Here's the real point I'm trying to convey...In ALL software design, your specs are important. You need to think about every aspect of what you want to do, what you NEED to do, and what information you are conveying to others. Start learning that now. If you mean X, don't say Y. If you mean "without using the built-in Math class methods", then that is what you should say. because "math functions" (with a lower case 'm') means all the functions of mathematics, as Mike implies.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
Here's the real point I'm trying to convey...In ALL software design, your specs are important. You need to think about every aspect of what you want to do, what you NEED to do, and what information you are conveying to others. Start learning that now. If you mean X, don't say Y. If you mean "without using the built-in Math class methods", then that is what you should say. because "math functions" (with a lower case 'm') means all the functions of mathematics, as Mike implies.


Exactly.Clear and precise communication is at the heart of all aspects of all successful software development endeavors. The syntax of the language is of vanishingly small importance when compared to making sure that all involved understand the requirements, constraints, options, and tradeoffs involved. Even poor design decisions, such as using bubblesort instead of mergesort, are often more easily fixed than a simple misunderstanding about how feature X is supposed to behave.

Of course, clearly and precisely communicating with the computer is also important. The compiler is, fortunately, a reliable and unforgiving master for the syntactical aspect of that, but we still have to be able to clearly and precisely express our logic if the code is to do what we want it to.

</soapbox>
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:Even poor design decisions, such as using bubblesort instead of mergesort

FOUL!!!

Best case for bubble sort is O(N). Best case for MergeSort is O(n log n).

So, if you do proper data analysis, there are cases where choosing bubble sort could be a good decision.
 
Gursewak Singh
Ranch Hand
Posts: 79
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry friend if you got confused by me
Problem is solved now
Actually i was going to code a program with did not use any maths build in function like sqrt,pow etc in c/c++.
so i use Newton equation as suggested by you
but for this i design my own code to calculate power etc.

Thanks a lot for discussion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!