Message Boards Message Boards

GROUPS:

How to fill Table with with for sentence?

Posted 1 year ago
2496 Views
|
1 Reply
|
1 Total Likes
|

enter image description hereSo i have this code, and I have Fx and Fy as components of force vector and rx and ry as move vector (x,y components). I don't have any issue with Force vector, but i would like to fill rx and ry vector with this form of data for n components:

rx1=l/2 * Sin [fi1],
rx2=l * Sin [fi1] + l/2 * Sin [fi2]
rx3=l * Sin [fi1] + l * Sin [fi2] + l/2 * Sin [fi3] and so on 

(I hope that pattern is recognizable, and for ry is the same only with cosines)

To write this by hand would take me too much time, so I am trying to use for sentence, but I am assuming I would use at least two FOR sentences and I have no idea how to do that.

You probably see where the problem is: each next element should have 1 element than the one before.

Thanks for your help.

Attachments:
Posted 1 year ago

Can you adapt this

n=3;
rx=Table[Sum[If[j<i,1,1/2]*I*Sin[Subscript[\[Phi],j]],{j,1,i}],{i,1,n}];
ry=Table[Sum[If[j<i,1,1/2]*I*Cos[Subscript[\[Phi],j]],{j,1,i}],{i,1,n}];

and then rx has the value

{(I/2)*Sin[Subscript[\[Phi], 1]],
 I*Sin[Subscript[\[Phi], 1]] + (I/2)*Sin[Subscript[\[Phi], 2]], 
 I*Sin[Subscript[\[Phi], 1]] + I*Sin[Subscript[\[Phi], 2]] + (I/2)*Sin[Subscript[\[Phi], 3]]}

and ry is similar with Cos

If you only wish to use For then

n=3;
rx=Table[0,{n}];
For[i=1,i<=n,i++,
  For[j=1,j<=i,j++,
    rx[[i]]=rx[[i]]+If[j<i,1,1/2]*I*Sin[Subscript[\[Phi],j]]
  ]
];

will give you the same values for rx and similar code with Cos will give you the same values for ry

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract