Ask Your Question

Abbas Jaffary's profile - activity

2023-03-01 18:35:57 +0200 received badge  Famous Question (source)
2021-11-16 21:32:49 +0200 received badge  Good Question (source)
2021-11-16 19:33:36 +0200 received badge  Nice Question (source)
2021-11-16 17:22:30 +0200 asked a question accessibility support

accessibility support Does Sage have accessibility support for Sage Math cells on the web? Navigating w/a screen reader

2021-11-03 19:30:08 +0200 received badge  Notable Question (source)
2021-06-30 18:59:34 +0200 marked best answer numpy cube root 'not callable'

I would like to plot the numpy.cbrt function in Sage.

The example:

import numpy as np
parametric_plot([u,np.sin(u)], (u,0,pi))

plots a sine wave, but

parametric_plot([u,np.cbrt(u)], (u,0,pi))

produces the error:

TypeError: loop of ufunc does not support argument 0 of type sage.symbolic.expression.Expression which has no callable cbrt method

Isn't Sage passing the interval [0,pi] as an array when constructing the plot? I'd like to know why some numpy functions will work in this manner with Sage, and why others do not, and if there is a workaround.

FWIW:
I am doing this to test numpy numerical precision vs. Sage built-in math functions. Numpy seems to be more precise, even using Sage RealField precision beyond 53 bits.

2021-06-30 18:59:34 +0200 received badge  Scholar (source)
2021-06-30 18:55:06 +0200 commented answer numpy cube root 'not callable'

Thank you. Incidentally, real_nth_root is what I wanted to compare against np.cbrt: x1 = cos(1).n() # Sage/Python sta

2021-06-30 16:41:08 +0200 asked a question numpy cube root 'not callable'

numpy cube root 'not callable' I would like to plot the numpy.cbrt function in Sage. The example: import numpy as np

2020-12-24 14:43:55 +0200 received badge  Popular Question (source)
2020-11-20 16:50:39 +0200 commented answer Path rendering on a Surface

Yes, same result.

2020-11-20 16:50:29 +0200 received badge  Supporter (source)
2020-11-20 10:31:38 +0200 received badge  Student (source)
2020-11-20 05:37:35 +0200 commented answer Path rendering on a Surface

Thank you -- fixed that (and above), still getting the same result. I reparametrized the path in polar coordinates as well, but I'm getting different values for r based on the rectangular --> polar conversion and the direct polar definition, for the same theta values. Curiously, the rectangular --> polar produces the closer z-coordinates.

2020-11-19 23:25:00 +0200 commented question Path rendering on a Surface

Thank you for pointing this out. I read https://stackoverflow.com/questions/6401167/how-do-i-pass-a-fraction-to-python-as-an-exponent-in-order-to-calculate-the-nth/6401264 (https://stackoverflow.com/questions/6...) and https://doc.sagemath.org/html/en/reference/rings_standard/sage/rings/rational.html (https://doc.sagemath.org/html/en/refe...), changed the exponents to floating point, but I get the same result.

2020-11-18 20:02:25 +0200 received badge  Editor (source)
2020-11-18 19:59:27 +0200 asked a question Path rendering on a Surface

I am having a discrepancy with the z-coordinates of a path on a surface.

The blue path shown below is correctly embedded in the red surface.

The z-coordinates for the green path are "almost" correct. I have gone over the math dozens of times. I need to compute rational powers of cosine and sine. Wondering if it could be a rounding issue?

The surface is parametrized in polar coordinates.

The path is parametrized in rectangular coordinates. (This is because on the full surface this portion is shifted along the x-axis. I reparametrized it polar and it seems less accurate).

What I've done is:

  1. Specify the path as $(x(u), y(u))$
  2. Compute the radial distance to the point $r(u) = \sqrt{x^2 + y^2}$
  3. The path is then given by $(x(u), y(u), z(r(u))$

(I've used the parameter $v$ to give the paths some "thickness")

This works fine for blue, not for green.

The surface height grows linearly with the radius.

The blue path's radius decays linearly.

The green path's radius decays non-linearly. But, I don't think that should matter, as I'm simply getting a list of points and plugging them into the height function.

u, v = var('u, v')
right_curve_u = 8+(14/pi)*(u+pi/2) #8+(14/pi)*(phi+pi/2)
f_x(u, v) = v*cos(u)
f_y(u, v) = v*sin(u)
f_z(u, v) = (((v-16)/12)*(12*cos((pi/11)*(right_curve_u - 17)) + 39.5))/12
T=parametric_plot3d([f_x, f_y, f_z], (u, -pi/2, 0), (v, 16, 28), color="red", opacity=0.5, axes=True, mesh=False)
#c=parametric_plot3d([f_x, f_y, f_z], (u, -pi/2, pi/2), (v, 21.9, 22.1), color="black", mesh=True)
#c is the curve in the first example with constant radius

#Path Equation;  Note, "u" is the parameter for the path, "v" is to give it a bit of "thickness"
right_curve_u = 8+(14/pi)*(u+pi/2) #8+(14/pi)*(phi+pi/2)
right_curve_x(u,v) = v*(16*(cos(u))^(5/6))
right_curve_y(u,v) = v*(-28*(sin(-u))^(5/6))
#right_curve_path_radius(u,v) = v*(16*28)/(((28*cos(u))^(2.4)+(16*sin(-u))^2.4)^(5/12))
right_curve_path_radius(u,v) = sqrt((right_curve_x)^2+(right_curve_y)^2)
right_curve_path_radius_2(u,v) = v*sqrt((16^2)*(cos(u))^(5/3)+(28^2)*(sin(-u))^(5/3))

right_curve_z(u,v) = ( ( (right_curve_path_radius - 16)/12 ) * ( 12*cos( (pi/11)*(right_curve_u - 17) ) + 39.5 ) )/12
right_curve_z_2(u,v) = ( ( (right_curve_path_radius_2 - 16)/12 ) * ( 12*cos( (pi/11)*(right_curve_u - 17) ) + 39.5 ) )/12

right_curve = parametric_plot3d([right_curve_x, right_curve_y, right_curve_z], (u, -pi/2, -0.01), (v, 0.99, 1.01), color="black")
right_curve_2 = parametric_plot3d([right_curve_x, right_curve_y, right_curve_z_2], (u, -pi/2, -0.01), (v, 0.99, 1.01), color="green")

g_x(u, v) = v*(16-(12*(u-pi/2)/pi))*cos(u)
g_y(u, v) = v*(16-(12*(u-pi/2)/pi))*sin(u)
h(u) = v*(16 - (12/pi)*(u-pi/2))
g_z(u,v) = ( ( (h - 16)/12 ) * ( 12*cos( (pi/11)*(right_curve_u - 17) ) + 39.5 ) )/12
c_xy=parametric_plot3d([g_x, g_y, g_z], (u, -pi/2, 0), (v, 0.99, 1.01), color="blue")
T+c_xy+right_curve+right_curve_2
2020-05-17 20:09:13 +0200 commented answer plotting a Surface gradient

Thank you for this! What a wonderful template. I was looking to do vectors tangent to the surface in the direction of the gradient -- I modified your code slightly https://sagecell.sagemath.org/?q=tzrxaj (here) and it looks beautiful!

v = vector([fx(dic), fy(dic), ((fx(dic))^2+(fy(dic))^2)])

and then changed it to negative gradient descent (to simulate gravity along the surface)

v = scale*v/nv*-1

Greatly appreciated. I have also playing with embedding https://sagecell.sagemath.org/?q=rxmfpk (curves in 3D onto a surface) -- giving the curves some "thickness" is an interesting exercise, working on automating it, along with generating vector fields on it as above.

2020-03-03 10:47:00 +0200 asked a question plotting a Surface gradient

I'm looking to plot the surface gradient vector field

$$\left \langle \frac{f_x}{\|\nabla f\|}, \frac{f_y}{\|\nabla f\|}, \|\nabla f\| \right \rangle$$

but only at points on the the surface $(x,y,f(x,y)$.

plotvectorfield3d will plot this field everywhere in 3D. I want to restrict this to the surface only.

Right now, I can plot these vectors individually by iterating along the surface, but I am wondering if someone has already tackled this more efficiently, perhaps with parameters on how to iterate.

Further, it would be nice to generalize this to directional derivatives for any unit vector $\mathbf{u} = \left \langle a, b \right \rangle$.