Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matrix Problem
#1
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
Reply
#2
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])]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  define a diagonal matrix from a matrix amalalaoui 1 2,319 May-15-2019, 01:12 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020