Ask Your Question
0

Why does solve() produces an error?

asked 2020-01-28 09:02:13 +0100

porton gravatar image

Why does solve() produces an error? TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.

#!/usr/bin/env python
# coding: utf-8

# In[2]:


var('Ex Ey Ez')


# In[3]:


E=vector([Ex,Ey,Ez])


# In[4]:


var('Px Py Pz')


# In[5]:


P=vector([Px,Py,Pz])


# In[6]:


var('LAx LAy LAz LBx LBy LBz')


# In[7]:


LA=vector([LAx,LAy,LAz]); LB=vector([LBx,LBy,LBz])


# In[8]:


var('k QAx QAy')


# In[9]:


QA=QAx*LA+QAy*LB


# In[20]:


solve(E-P==k*(E-QA), [k, QAx, QAy])


# In[24]:


solve((E-P).cross_product(E-QA)==0, [QAx, QAy])
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-28 09:32:34 +0100

Emmanuel Charpentier gravatar image

(E-P).cross_product(E-QA is a vector (technically a free module...), not a list. So:

sage: solve(list((E-P).cross_product(E-QA)),(QAx, QAy))
[[QAx == -(Ez*LBy*Px - Ey*LBz*Px - (Ez*LBx - Ex*LBz)*Py + (Ey*LBx - Ex*LBy)*Pz)/(Ez*LAy*LBx - Ey*LAz*LBx - (Ez*LAx - (Ex - Px)*LAz)*LBy + (Ey*LAx - (Ex - Px)*LAy)*LBz + (LAz*LBx - LAx*LBz)*Py - (LAy*LBx - LAx*LBy)*Pz), QAy == (Ez*LAy*Px - Ey*LAz*Px - (Ez*LAx - Ex*LAz)*Py + (Ey*LAx - Ex*LAy)*Pz)/(Ez*LAy*LBx - Ey*LAz*LBx - (Ez*LAx - (Ex - Px)*LAz)*LBy + (Ey*LAx - (Ex - Px)*LAy)*LBz + (LAz*LBx - LAx*LBz)*Py - (LAy*LBx - LAx*LBy)*Pz)]]
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

1 follower

Stats

Asked: 2020-01-28 09:02:13 +0100

Seen: 305 times

Last updated: Jan 28 '20