Quantcast
Channel: ASKSAGE: Sage Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 4

Answer by John Palmieri for I am trying to plot the following function:x = var('x') def y(x): return RR(len(prime_range(floor(0.95 * x), floor(1.25 * x))) / round(1.25 * x - 0.95 * x)) I am not sure whether it is well-constructed mathematically, but it's trying to check the density of prime numbers around a given value x I am using the floor() function because I'm not sure that prime_range() accepts non-integers.If I test the function with random real values of x I get a plausible output without errors.However, when I try to plot the function as in:plot(y(x), (x, 5, 20)) I get the following error message:TypeError: unable to convert floor(0.950000000000000*x) to an integer and argument is also not real: unable to simplify to float approximation I don't understand why this input cannot be understood as real by sagemath, or why the floor is not an integer.

Next: Comment by John Palmieri for I am trying to plot the following function:x = var('x') def y(x): return RR(len(prime_range(floor(0.95 * x), floor(1.25 * x))) / round(1.25 * x - 0.95 * x)) I am not sure whether it is well-constructed mathematically, but it's trying to check the density of prime numbers around a given value x I am using the floor() function because I'm not sure that prime_range() accepts non-integers.If I test the function with random real values of x I get a plausible output without errors.However, when I try to plot the function as in:plot(y(x), (x, 5, 20)) I get the following error message:TypeError: unable to convert floor(0.950000000000000*x) to an integer and argument is also not real: unable to simplify to float approximation I don't understand why this input cannot be understood as real by sagemath, or why the floor is not an integer.
$
0
0
Use `plot(y, (x, 5, 20))` — use `y` instead of `y(x)`. When you pass `y(x)` as an argument, where `y` is a Python function, it gets evaluated right away: it doesn't plug in different values for `x`, it just tries to evaluate `y(x)` as a number. That's where the error messages come from. If you plug in `y` instead, it tests to see if it is a function and if so, it plugs in `x`-values in the given range.

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images