Ask Your Question

curios_mind's profile - activity

2024-04-16 21:17:58 +0200 received badge  Popular Question (source)
2024-04-16 21:16:39 +0200 received badge  Notable Question (source)
2024-04-16 21:16:39 +0200 received badge  Popular Question (source)
2024-02-26 17:09:18 +0200 received badge  Famous Question (source)
2023-07-05 10:37:50 +0200 received badge  Notable Question (source)
2023-04-28 06:11:55 +0200 received badge  Notable Question (source)
2023-03-04 18:41:41 +0200 received badge  Notable Question (source)
2023-03-04 18:41:41 +0200 received badge  Popular Question (source)
2022-12-30 20:17:03 +0200 received badge  Popular Question (source)
2022-10-05 14:31:41 +0200 received badge  Popular Question (source)
2022-05-16 05:39:58 +0200 received badge  Popular Question (source)
2021-02-08 15:05:08 +0200 commented answer vector_field.apply_map before and after vector.display (weird behaviour)

Your explanation makes sense, though I thought when the vector_field is called, as in the question, the corresponding representation of the field in spherical chart is updated.

2021-02-08 14:54:22 +0200 commented answer Divergence of inverse square

It would have been great, if it had given the dirac solution.

2021-02-07 04:27:55 +0200 asked a question vector_field.apply_map before and after vector.display (weird behaviour)

Hello,

Recently, I have come a cross a very weird behaviour with vector_field.apply_map function. Here is the case:

Consider the following code:

E.<r,th,ph>=EuclideanSpace(coordinates="spherical",start_index=0)

cart.<x,y,z>=E.cartesian_coordinates()
cartf=E.cartesian_frame()

spherf=E.spherical_frame()

E.set_default_frame(cartf)

Now, if I create a vector field, substitute ph with ph_1 and th with th_1, and then display the resultant vector as

var("r_1 th_1 ph_1")
v=E.vector_field([r_1,0,0], frame=spherf, chart=cart);
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1));show(v.display())

I get 0 printed

However,

If I do the same, but this time if I add show(v.display()) before calling apply_map function as

var("r_1 th_1 ph_1")
v=E.vector_field([r_1,0,0], frame=spherf, chart=cart); show(v.display())
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1));show(v.display())

I get

 r_1 cos(ph)sin(th) e_x + r_1 sin(ph)sin(th) e_y + r_1 cos(th) e_z
 r_1 cos(ph_1)sin(th_1) e_x + r_1 sin(ph_1)sin(th_1) e_y + r_1 cos(th_1) e_z

printed (as expected).

Why does the display function affect the substitution?

2021-02-07 00:15:43 +0200 asked a question Divergence of inverse square

Hello,

I tried to calculate the divergence of 1/r^2e_r, but I got zero, where it should have been 4pidirac_delta(re_r)

E.<r,th,ph>=EuclideanSpace(coordinates="spherical")
v=E.vector_field([1/r^2,0,0])
v.div().display()

Results is

E^3 --> R
(r, th, ph) |--> 0

Can this be considered as a bug?

2021-02-02 01:01:18 +0200 received badge  Good Question (source)
2021-02-01 14:26:50 +0200 received badge  Nice Question (source)
2021-02-01 12:30:45 +0200 commented answer subs in vector field

I had the same confusion. There is the subs function, but doesn't do the job. Don't you guys think that this is a bug?

2021-02-01 04:11:15 +0200 asked a question subs in vector field

Hello,

var('a')
E.<x,y,z>=EuclideanSpace()
vf=E.vector_field([a**2,a*x,a*x*y]) # arbitrary vector field
vf.subs(a==1).display()

gives back the vector field without substituting the value of a

a^2 e_x + a*x e_y + a*x*y e_z

How does the funciton subs work with vector fields?

Thanks alot for your help.

2021-01-30 23:43:42 +0200 commented answer 2 sets of coordinates in EuclideanSpace?

Thank you so much! this is really awesome. I love the way sagemath handle these things.

2021-01-30 23:42:57 +0200 received badge  Supporter (source)
2021-01-29 21:28:08 +0200 asked a question 2 sets of coordinates in EuclideanSpace?

Hello,

I would like to work with 2 vectors in EuclideanSpace each having x1,y1,z1 and x2,y2,z2 coordinates. I will be needing to switch back and forth between cartesian and spherical coordinates as well.

As an example, say, (r1,0,0) -> (x1,y1,z1) while (r2,0,0)->(x2,y2,z2) in the same EuclideanSpace.

How would one work with multiple vectors (with independent coordinates) in EuclideanSpace?

Should one define 2 chart for spherical coordinates and 2 for cartesian coordinates?

Or should one create 2 different EuclideanSpace and combine them (if possible)?

2021-01-29 14:26:30 +0200 commented answer Matrix multiplication with a vector in EuclideanSpace

Thank you very much. This really helped and saved me from a lot of trouble.

2021-01-29 01:25:10 +0200 asked a question Matrix multiplication with a vector in EuclideanSpace

Hello

Oversimplified version of my question is "How can I multiply a vector with a matrix?"

E.<x,y,z>=EuclideanSpace(start_index=0)
vf=E.vector_field([x*y,x^2,z**2]) # the components are for testing purposes

M=Matrix(RR,3,3);M[:]=1 # this is just a test
# Neither this
M*vf
# nor this works
M*vf.at(E((3,2,1)))

The only work around I could think of is

v=vf.at(E((3,2,1)))
q=vector([v[0],v[1],v[2]])
M*q

or directly on the vector field

v=vector([v[0].expr(), v[1].expr(), v[2].expr()])
M*q

With this approach I have to put the transformed components back in the vector field defined within EuclideanSpace.

I would like to use EuclideanSpace to work with vectors.

Is there an easy way to handle this? Basically I am looking for an easy way to transform a vector field defined in EuclideanSpace?

Thanks in advance for your help.

2020-07-06 20:18:16 +0200 commented answer plot_vector_field3d in spherical coordinates

Is there a way to increase density of the vectors? It is also very slow. Is there a way to speed it up?

2020-07-05 23:00:12 +0200 answered a question How do I solve cos(2*t)==sin(t)

You could try

var('t')
solve(cos(2*t)==sin(t),t,to_poly_solve='force')

which gives [t == -1/2*pi - 2*pi*z24, t == 1/6*pi + 2/3*pi*z25]

Z's are integers.

2020-07-05 22:47:56 +0200 asked a question Metric of EuclideanSpace(3) in spherical frame

I may have some conceptual misunderstandings, but here is the code

E=EuclideanSpace(3)
c_spher.<r,th,ph>=E.spherical_coordinates()
f_spher=E.spherical_frame()

E.set_default_chart(c_spher)
E.set_default_frame(f_spher)

g=E.metric()
show(g[:])

I was expecting the diagonal elements of the metric to be [1,r^2,r^4*sin(th)^2], but I get [1,1,1]

What I am doing wrong?

2020-07-05 22:29:52 +0200 commented answer plot_vector_field3d in spherical coordinates

Thank you so much.

Yep, I made typos. Sorry for that. The code was on another computer, I was typing it it.

2020-07-04 19:02:31 +0200 answered a question How to find all maximum length lists with a nested and display?

As the other contributors have said, you can simply use python.

Just another version:

a=[[1,3],[4,5,6],[2,3,4,6,7],[1,3]]
givememaxlen=lambda x: max([len(i) for i in x]);
print(givememaxlen(a))
2020-07-04 12:48:23 +0200 asked a question plot_vector_field3d in spherical coordinates

Hello,

How can I draw a vector field in spherical coordinates?

For example

E=EuclideanSpace(3)
c_cart.<x,y,z>=E.cartesian_coordinates()
c_spher.<r,ph,th>=E.spherical_coordinates()

f_spher=E.frames()[2] # frame in spherical coordinates
E.set_default_chart(c_spher)
E.set_default_frame(f_spher) 

vf=E.vectorfield((r,0,0), frame=f_spher,cart=c_spher,name="vf");show(vf.display())

This beutifully gives me a vector field as r e_r

Now, I would like to plot this field in spherical coordinates

plot_vector_field3d([c.expr() for c in vf[:]], (r,2,10),(th,0,pi),(ph,0,2*pi))

I also tried out the transformation keyword as it is in plot3d function, but it still plots r as x. How can I plot the vector field in spherical coordinates? I was expecting to see outgoing arrows in all directions from r=2 to 10?

2020-06-23 00:14:23 +0200 received badge  Nice Question (source)
2020-06-22 23:19:56 +0200 commented answer assume gives false for a<oo

Thanks for the clarification. I think it is an important point of view.

2020-06-22 18:52:47 +0200 marked best answer solve: Possible bug?

Hello,

This question is relevant to Question #2 in the topic "desolve: wrong solution?!". If desolve is using solve internally when initial conditions are invoked to find the constants after obtaining the general solution, perhaps this is where the problem lies.

Consider the following expression

a=var('a')
f=-1/2*(I*sqrt(3)*2^(1/3) - 2^(1/3))/(-2*a - 1)^(1/3)
sol=solve(f==-2,a);show(sol)

sol is [a == (-5/8)]

Now, if we plug that back in f,

check=f.subs(sol).n();print(check`)

this gives 1.00000000000000 - 1.73205080756888*I, where it ought to give -2 (if there is a solution)

And I tried this with Mathematica also

Solve[-1/2 (I Sqrt[3] 2^(1/3) - 2^(1/3))/(-2 a - 1)^(1/3) == -2, a]

It returns an empty list {} for this, indicating that there is no solution.

What is wrong with Sage's solve function here?

Update: I tried solve with "sympy" agorithm. It agreed with Mathematica. It looks like there is a problem with Maxima

2020-06-21 18:42:01 +0200 asked a question assume gives false for a<oo

Hello

reset()
var('a')
assume(a<99)
print(bool(a<+Infinity)) # or print(bool(a<oo))

Why does this code print False.

2020-06-21 03:57:16 +0200 commented question Another: dirac_delta integration: possible bug?

I looked at the code and tried to fix it to accomodate this problem but I wasn't very successful (though I learned a lot!) I tried the following with your version, but I am getting 0.

assume(a>-2)
assume(a<2)
integrate_delta(dirac_delta(x^2-a),x,-100,100)

am I using it wrong? (especially the assumptions?)

2020-06-21 03:57:16 +0200 received badge  Commentator
2020-06-20 15:21:20 +0200 marked best answer Integration of dirac_delta

Hello,

When I tried to integrate the following

(dirac_delta(x)).integrate(x,-pi,pi)

I get 1 (as expected)

But when I integrate

(dirac_delta(cos(x))).integrate(x,-pi,pi)

I get integrate(dirac_delta(cos(x)), x, -pi, pi) back. I would expect to get 2 since there are two points which are zero between the upper and lower bounds of the integral. So by any means of approaching these points with limit during the integration, the integral of dirac_delta should have returned 1 for each point which adds up to 2

If I try the same with Mathematica,

Integrate[DiracDelta[x], {x, -Pi, Pi}]

I get 1 and when I try

Integrate[DiracDelta[Cos[x]], {x, -Pi, Pi}]

I get 2 as I would expect.

What is the reason of this behaviour of Sage?