Python Forum

Full Version: Matrix Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I'm a beginner in Python language and I've got a little problem with a matrix I tried to encode.
I want to have these vectors :
 [[          0                                                                       ]
  [ - l*cos(q_tri[:,1])                                                              ]
  [ - l*cos(q_tri[:,1]) - l*cos(q_tri[:,2])                                          ]
  [ - l*cos(q_tri[:,1]) - l*cos(q_tri[:,2]) - l*cos(q_tri[:,3])                      ]
  [ - l*cos(q_tri[:,1]) - l*cos(q_tri[:,2]) - l*cos(q_tri[:,3]) - l*cos(q_tri[:,4])  ]]  for Yn[]

and

 [[           0                                                                     ]
  [  l*sin(q_tri[:,1])                                                              ]
  [  l*sin(q_tri[:,1]) + l*sin(q_tri[:,2])                                          ]
  [  l*sin(q_tri[:,1]) + l*sin(q_tri[:,2]) + l*sin(q_tri[:,3])                      ]
  [  l*sin(q_tri[:,1]) + l*sin(q_tri[:,2]) + l*sin(q_tri[:,3]) + l*sin(q_tri[:,4])  ]]  for Xn[]
But I couldn't be successful ...

Here what I tried to do :
Xn = [0]
for a in range (0,n):
Xn.append(L*np.sin(q_tri[:,a]))

Yn = [0]
for b in range (0,n):
Yn.append(-L*np.cos(q_tri[:,b]))
Here q_tri[] is of size n.
I also tried two for loops but it didn't work either.

Thank you for the time you'll pass on it, I know it would'nt be that hard Dodgy
I am not sure what do you exactly want and what is shape of q_tri. If its just array with (1, 5) shape, then perhaps adding sum into your for loop will do it.
Output:
In [2]: q_tri = np.arange(5).reshape(1,-1) In [3]: q_tri Out[3]: array([[0, 1, 2, 3, 4]]) In [4]: Xn = [] ...: L = 3 ...: for a in range(5): ...: Xn.append(L * np.sum(np.sin(q_tri[:,1:a+1]), axis=1)) ...: In [5]: Xn Out[5]: [array([ 0.]), array([ 2.52441295]), array([ 5.25230523]), array([ 5.67566526]), array([ 3.40525777])]