Ask Your Question
0

"==" with symbolics is doing unwanted boolean comparison

asked 2024-06-25 00:08:59 +0100

updated 2024-06-26 12:22:14 +0100

Emmanuel Charpentier gravatar image

parameters

var('v0 t', domain='positive')  

#generic funtions  
x_a = function('x_a')(t)  
y_a = function('y_a')(t)  
x_b = function('x_b')(t)  
y_b = function('y_b')(t)  
x_c = function('x_c')(t)  
y_c = function('y_c')(t)  

r_a = vector([x_a, y_a])  
r_b = vector([x_b, y_b])  
r_c = vector([x_c, y_c])  

eq_a = diff(r_a, t) == v0*(r_b - r_a)/(r_b - r_a).norm() #this evaluates as boolean
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2024-06-25 16:38:17 +0100

Max Alekseyev gravatar image

It is convenient to keep equations in the form expression == 0 and furthermore functions dealing with equations will typically understand a given expression as an equation of that form. Hence, you can avoid using == in favor of using the difference between the lhs and rhs:

eq_a = diff(r_a, t) - v0*(r_b - r_a)/(r_b - r_a).norm()

If you still want to get explicit equations with == from the above vector - here is a way:

eq_a_eq = [eq==0 for eq in eq_a]
edit flag offensive delete link more
0

answered 2024-06-25 08:28:40 +0100

Emmanuel Charpentier gravatar image

Well... vector/matrix equations are a tad awkward :

sage: from _operator import eq
sage: vector(map(eq, diff(r_a, t), v0*(r_b - r_a)/(r_b - r_a).norm()))
(diff(x_a(t), t) == -v0*(x_a(t) - x_b(t))/sqrt(abs(-x_a(t) + x_b(t))^2 + abs(-y_a(t) + y_b(t))^2), diff(y_a(t), t) == -v0*(y_a(t) - y_b(t))/sqrt(abs(-x_a(t) + x_b(t))^2 + abs(-y_a(t) + y_b(t))^2))

$$ \left(\frac{\partial}{\partial t}x_{a}\left(t\right) = -\frac{v_{0} {\left(x_{a}\left(t\right) - x_{b}\left(t\right)\right)}}{\sqrt{{\left| -x_{a}\left(t\right) + x_{b}\left(t\right) \right|}^{2} + {\left| -y_{a}\left(t\right) + y_{b}\left(t\right) \right|}^{2}}},\,\frac{\partial}{\partial t}y_{a}\left(t\right) = -\frac{v_{0} {\left(y_{a}\left(t\right) - y_{b}\left(t\right)\right)}}{\sqrt{{\left| -x_{a}\left(t\right) + x_{b}\left(t\right) \right|}^{2} + {\left| -y_{a}\left(t\right) + y_{b}\left(t\right) \right|}^{2}}}\right) $$

HTH,

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2024-06-25 00:06:10 +0100

Seen: 182 times

Last updated: Jun 26