Questions tagged [math.sqrt]

Using the Math package (in different programming languages) method sqrt to calculate the square root of a value.

77 questions
0
votes
1 answer

Ruby - Sqrt on a very large Integer cause Rounding issues

I'm trying to solve a Fibonacci problem and am stumbling into rounding issues. If i = 8670007398507948658051921 then fib1 = 19386725908489880000000000.0. My code is below - thanks for any help. def is_fibonacci?(i) fib1 = Math.sqrt(5*(i**2)+4) …
eadon
  • 13
  • 1
  • 4
-1
votes
1 answer

What's wrong in my code???ValueError: math domain error Python -sqrt

import math a,b,c = map(int,input().split()) x = float((-b + math.sqrt(b**2-4*a*c))/2*a) y = float((-b - math.sqrt(b**2-4*a*c))/2*a) if y>x: x = x1 y = x x1 = y if (b**2-4*a*c >=1): print("Two different roots "+"x1=",int(x)," ,…
-1
votes
1 answer

How to implement pow(x) and sqrt(x)?

I tried looking for a similar answer, but didn't find anything. So here goes. I am currently tasked with creating a simple calculator with a GUI in Python using the tkinter tools. I was almost done when I ran into some problems implementing pow(x)…
-1
votes
1 answer

Square negative number in go

I'm having problems to square a negative number in go... (2*(1-0.5)-4)/((4*(4-2))/(2-1))^(1/2) = -1.06066017 but with go I get NaN package main import ( "fmt" "math" ) func main() { fmt.Print(math.Sqrt((2*(1-0.5) - 4) / ((4 * (4 - 2)) /…
-1
votes
1 answer

Python Plot- Multiple the data in plot figure

I am reading data from a text file but when I do so, I need to multiple this values like 3*sqrt(col1)= x1.append(3*math.sqrt(float(p[1]))) in plot function. How can I multiple column number data before plotting? For example, I will multiple col3…
Nobody
  • 79
  • 13
-1
votes
1 answer

SyntaxError: Invalid Syntax in math.sqrt in Python

I tried this import math from math import sqrt def euclideanDistance(xtr, ytr, Ltr): distance = 0 for x in range(Ltr): distance += pow((xtr[x] - ytr[x]), 2) return sqrt(distance) But it returned me the following error: File "", line 5 …
Rifat
  • 3
  • 1
  • 3
-1
votes
1 answer

Count triangle area - working as vars but not wrapped as a function

A noob question. I am playing with http://www.w3resource.com/javascript-exercises/javascript-basic-exercises.php#EDITOR javascript exercises. Exercise number 4. Count the area of a triangle. Why this works: var a = 5; var b = 6; var c = 7; var p =…
Mac_W
  • 2,927
  • 6
  • 17
  • 30
-1
votes
1 answer

Math.Sqrt() when using BigInteger?

I need to make a Math.Sqrt calculation but it must support really big numbers so I'm trying to use BigInteger but Math.Sqrt doesn't support them. Are there any other options? How can I do this calculation and result is double ? Sample : sqrt 5 =…
CarlesBerg
  • 33
  • 4
-2
votes
4 answers

Can someone explain this number = 80; number = (int)math.sqrt(number++) ; number = 8?

int number; number = 80; number = (int)math.sqrt(number++) System.out.println(number) This is the above code. I am new to programming and have a decent under standing of mathematics. I am aware the SQRT is 8. However in this case i am…
JAVAJoseph
  • 31
  • 9
-2
votes
2 answers

Math.sqrt showing error in Eclipse

This is the code for a calculator app for Android I'm making: package com.example.calculator; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Iterator; import java.util.Stack; import java.lang.Math; import…
user2201935
  • 396
  • 1
  • 7
  • 19
-4
votes
2 answers

Math.pow and Math.sqrt in Java

Okay, I have found 2 short codes that work, but I want to understand how they work. I have googled and check the links such as: http://www.tutorialspoint.com/java/lang/math_pow.htm http://www.tutorialspoint.com/java/lang/math_sqrt.htm But the…
Acemi
  • 173
  • 1
  • 4
  • 13
-5
votes
1 answer

How to get Square root of a number without import anything in python?

How to get Square root of a number without import anything in python? You know we can do this: import math a = 4 s = math.sqrt(a) but i want do this more simple without import any library.
Kasra Najafi
  • 560
  • 5
  • 11
-5
votes
4 answers

Return value of math.sqrt

I have been try to draw the function of y^2=4*a*x but I have run into a problem. when I use the math.sqrt function to find the square root of a value which has two answer +or- something i only get the positive value. i.e if i found the sqrt of 4 it…
opeyemi
  • 83
  • 1
  • 9
-6
votes
3 answers

Finding largest square less than a given number in Java

I want to write a java program to find the largest square number which is less than or equal to a given number. For example when I insert 10 as the inputted number, the answer is 9 because 9is the largest square up to 10 I understand loops, but I…
kago
  • 47
  • 8
-6
votes
2 answers

Java math issue

Can any one tell me how to write this type of code in eclipse propject. basically i want to square root the samv and samvi variables. i am getting syntax error. int ki, l,; int samv = (tdrum / k) / l; int samvi = (tdrum / ki) / l; int samv2 =…
Monika
  • 74
  • 7