Questions tagged [square-root]

A square root of a number A is a number y such that y^2 = A, or, in other words, a number y whose square (the result of multiplying the number by itself, or y × y) is A.

A square root of a number A is a number y such that y2 = a, or, in other words, a number y whose square (the result of multiplying the number by itself, or y × y) is A.

398 questions
-1
votes
1 answer

Error with square root function and powers in Matlab R2014b

I am carrying out a series of calculations using the sqrt() function. My colleagues and I have noticed that we get different results when using the same inputs. Has anyone encountered this problem before? This is an example: input1 = 4; input2 =…
-1
votes
1 answer

Trouble with float on C

I have this little program in C that calculates the square root x of a positive integer N using a recursive function (implemented using a while loop). If I calculate x using this: x = (1/2)*(x + N/x) //x0 = 1.0 Then x keeps growing to inf and then…
-1
votes
1 answer

My variable always becomes a zero

I have a problem with my C++ code where Im doing two steps in one with regards to pythagoras. Im getting the length of a and b at the same time as doing the pythagoras function but my variable always equals 0 even though the X and Y points show up…
Harvey
  • 1,320
  • 3
  • 13
  • 33
-1
votes
2 answers

self checking test bench for square root algorithm

I have written verilog code for a non-restoring square root algorithm which is synthesisable. My senior says that it now requires a self checking testbench. I know that there is an operator $sqrt in verilog, which is applicable to real numbers. I am…
savitri
  • 13
  • 2
-1
votes
2 answers

Square root and def function?

As I've progressed a little more in Python I thought I would try out the define function. I've made this simple square root calculator. Please explain as simple as you can? import math def mathprob(x): math.sqrt(x) yn = input() num =…
user2340615
  • 171
  • 3
  • 4
  • 10
-1
votes
2 answers

How can I make a recursive square root in Python?

I've got this code: def root(x,n): if n==0: return x else: return 0.5**(x/root(x,n-1)+root(x,n-1)) but: >>>root(4,2) >>>2.05 Why? And it doesn't work with other square roots...
Santiago VdeK
  • 72
  • 2
  • 13
-2
votes
1 answer

x**-0.5: what is the - before ** performing?

while finding a square-root, we perform number**0.5, but what is the meaning of - sign before 0.5. I was looking at a code (I was specificially looking at ViT Code, and here for scaling, they have added: self.scale = self.head_dim ** -0.5 Please…
-2
votes
1 answer

Find Standard deviation for each column of array

I am to find the standard deviation. When calculating the standard deviation, my outputs are way higher than the given sample. How do I go calculating the standard deviation of each column? Here is my code as reference: double[] average = new…
user19598384
-2
votes
2 answers

How to find out whether two numbers are powers of the same number and those powers

So say you are given the numbers 27 and 81. How would a program that tells you that the 4th root of 81 is 3 and the cubic root of 27 is three. (Both have the root of 3). x = 16; y = 4; foo = same_root(16, 4); // foo = 2 root1 = find_root(16, 2);…
-2
votes
1 answer

Why does my code give runtime error timeout?

I just want to add the sqrt of n to the divisors vector if its integer but everytime I try the code It goes Haywire. My vector.push_back(sqrt(n)) Function is giving the problem I sense. Runtime error occurs . But when I remove those 3 Lines it…
Akhil Vaid
  • 11
  • 1
  • 10
-2
votes
1 answer

Why do we only check up to the square root of a prime number to determine if it is prime? Can't we use cube root?

If a number n can be written as axb and m=sqrt(n). Here n=m*m. We say we only need to check upto m because min(a,b)<=m. So cant we take cube roots? Suppose we take n=21, then n=1x3x7. But Cube root is 2. Why does this method fail?
-2
votes
1 answer

Logic concerning negative num inputs being converted to positive num inputs

Maybe I'm asking google all the wrong questions but I scoured the internet and could not find posts similar to my unique problem. This is a simple coding challenge from FreeCodeCamp: I need to work on the function abTest(a,b) where when a OR b is…
-2
votes
3 answers

How to Print Out the Square Root of A Negative Number with i Displayed in C

I am trying to figure out how to display the square root of a number if it happens to be negative (as it is entered by the user), and if so, display it correctly with the "i" displayed as well. When I do the normal sqrt function, the result is…
-2
votes
4 answers

Sqrt and decimals

Is there any standard number of decimals needed to be able to reconstitute a number from it's sqrt decomposition with an error < 1 ? I mean this : sqrt(200000) = 447.21359 ... If I try to do rebuild my number with only two decimals I have …
-2
votes
1 answer

grouping of bits in square root division

I have written verilog code for square root of a number which is parametrised. If the number of bits are even the code works. If the number of bits are odd, the code divides the number of bits into groups of two starting from the right (LSB). The…
savitri
  • 13
  • 2