Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.8K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Subtract of vectors, subtracts whole vector from individual elements

Posted 6 years ago

When I'm trying to calculate the value of DP, it subtracts the PCurrent matrix from each element of PGoal. What am I doing wrong?

OP4 = MatrixForm[{Cos[
      T1] (L1 + L2 Cos[T2] + L3 Cos[T2 + T3]), (L1 + L2 Cos[T2] + 
       L3 Cos[T2 + T3]) Sin[T1], L2 Sin[T2] + L3 Sin[T2 + T3]}];
OP4 = OP4 /. {L1 -> 0.3, L2 -> 0.3, L3 -> 0.15}
Print["OP4=", MatrixForm[OP4]];
OJTrans = 
  MatrixForm[{{(-(L1 + L2 Cos[T2] + L3 Cos[T2 + T3])) Sin[T1], 
     Cos[T1] ((-L2) Sin[T2] - L3 Sin[T2 + T3]), ((-L3) Cos[T1]) Sin[
       T2 + T3]}, {Cos[T1] (L1 + L2 Cos[T2] + L3 Cos[T2 + T3]), 
     Sin[T1] ((-L2) Sin[T2] - L3 Sin[T2 + T3]), ((-L3) Sin[T1]) Sin[
       T2 + T3]}, {0, L2 Cos[T2] + L3 Cos[T2 + T3], L3 Cos[T2 + T3]}}];
OJTrans = OJTrans /. {L1 -> 0.3, L2 -> 0.3, L3 -> 0.15}
ThetaInitial = {{0}, {Pi/4}, {Pi/2}};
PGoal = {{0.35}, {0.05}, {0.35}};
Print["PGO=", MatrixForm[PGoal]];
ThetaEstimate = ThetaInitial;
For[i = 1, i <= 5, i++,
  Print["IterationNumber", i];
  PCurrent = 
   OP4 /. {T1 -> ThetaEstimate[[1, 1]], T2 -> ThetaEstimate[[2, 1]], 
     T3 -> ThetaEstimate[[3, 1]]};
  Print["PCurrent=", MatrixForm[PCurrent]];
  DP = PGoal - PCurrent;
  Print["DP=", MatrixForm[DP]];
  ];

This is what I'm getting

SequenceForm["DP=", 
MatrixForm[{{
   0.35 - MatrixForm[{0.4060660171779821, 0., 0.3181980515339463}]}, {
   0.05 - MatrixForm[{0.4060660171779821, 0., 0.3181980515339463}]}, {
   0.35 - MatrixForm[{0.4060660171779821, 0., 0.3181980515339463}]}}]]
POSTED BY: Anshuman Singh
Posted 6 years ago

That is how Subtract works. From the documentation "Subtract threads element-wise over list"

{1, 2, 3, 5} - .5
(* {0.5, 1.5, 2.5, 4.5} *)

{1, 2, 3, 5} - {5, 4, 3, 2}
(* {-4, -2, 0, 3} *)

What result were you expecting?

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