Processing math: 100%
Ask Your Question
0

"==" with symbolics is doing unwanted boolean comparison

asked 0 years ago

monkeyboy gravatar image

updated 0 years ago

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
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 0 years ago

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]
Preview: (hide)
link
0

answered 0 years ago

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))

(txa(t)=v0(xa(t)xb(t))|xa(t)+xb(t)|2+|ya(t)+yb(t)|2,tya(t)=v0(ya(t)yb(t))|xa(t)+xb(t)|2+|ya(t)+yb(t)|2)

HTH,

Preview: (hide)
link

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: 0 years ago

Seen: 228 times

Last updated: Jun 26 '24