Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.3K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to use results of a loop?

Posted 7 years ago

Hi all,

I would like to use the results of an expression performed in a Table, Do loop, or other loop operations, for further calculations, but I do not know how to.

I want to find the theta angles for different ThetaP angles using the FindRoot function: `Lp = 180; L1 = 150; L2 = 420; L3 = 460; [Theta]1 = 30 [Degree] ;

Table[res1 = FindRoot[{450 == Lp Cos[[Theta]p] + L1 Cos[[Theta]1] + L2 Cos[[Theta]2] + L3 Cos[[Theta]3], 530 == Lp Sin[[Theta]p] + L1 Sin[[Theta]1] + L2 Sin[[Theta]2] + L3 Sin[[Theta]3]}, {{[Theta]2, 90 [Degree]}, {[Theta]3, 10 [Degree]}}], {[Theta]p , 180, 185}]`

This Table gives me results of Theta2 and Theta3 for certain interval of ThetaP. Now I would like to perform multiple operations for each of the combinations of Theta2 and Theta3. E.g. those calulations: {xp, yp} = { Lp Cos[\[Theta]p], Lp Sin[\[Theta]p]} ; {x1, y1} = {xp + L1 Cos[\[Theta]1], yp + L1 Sin[\[Theta]1]} ; {x2, y2} = {x1 + L2 Cos[\[Theta]2], y1 + L2 Sin[\[Theta]2]}; {x3, y3} = {x2 + L3 Cos[\[Theta]3], y2 + L3 Sin[\[Theta]3]} ;

Can I execute those calculations inside the Table function, or is there a way how to refer to those results later?

Another question: In this example I have fixed the value of Theta1, so the system of nonlinear equations is solvable. But in the future I would like also Theta1 to be free. This way I will have 3 unknowns and 2 equations. Any suggestions will be appreciated.

Regards,

Jurij

POSTED BY: Jurij Hladnik
2 Replies
Posted 7 years ago

Hi,

I managed to extract the results and use them in each iteration of ?2 and ?3 something like this:

Table[{c = FindRoot[{450 == Lp Cos[?p] + L1 Cos[?1] + L2 Cos[?2] + L3 Cos[?3], 530 == Lp Sin[?p] + L1 Sin[?1] + L2 Sin[?2] + L3 Sin[?3]}, {{?2, 90 °}, {?3, 10 °}}],

?2[?p] = ?2 /. c, ?3[?p] = ?3 /. c,

{xp[?p], yp[?p]} = {Lp Cos[?p], Lp Sin[?p]}; {x1[?p], y1[?p]} = {xp + L1 Cos[?1[?p]], yp + L1 Sin[?1[?p]]};

}, {?p, 180 °, 185 °}]

I can not check the correctness of the written line, because I don't have Mahematica on this computer. Thank you very much for your help,

Jurij

POSTED BY: Jurij Hladnik
Posted 7 years ago

Jurij,

I think {?p, 180, 185} should probably be {?p, 180 °, 185 °} unless you intended radians.

root = Table[
  FindRoot[{450 == Lp Cos[?p] + L1 Cos[?1] + L2 Cos[?2] + L3 Cos[?3], 
    530 == Lp Sin[?p] + L1 Sin[?1] + L2 Sin[?2] + L3 Sin[?3]}, 
    {{?2, 90 °}, {?3, 10 °}}], {?p, 180 °, 185 °}]

(* {{?2 -> 1.47161, ?3 -> 0.0806623}} *)

The next part of your question is not clear to me. Evaluating the code

{xp, yp} = {Lp Cos[?p], Lp Sin[?p]};
{x1, y1} = {xp + L1 Cos[?1], yp + L1 Sin[?1]};
{x2, y2} = {x1 + L2 Cos[?2], y1 + L2 Sin[?2]};
{x3, y3} = {x2 + L3 Cos[?3], y2 + L3 Sin[?3]};

Gives

{{xp, yp}, {x1, y1}, {x2, y2} {x3, y3}}
(*
{{180 Cos[?p], 180 Sin[?p]},
 {75 Sqrt[3] + 180 Cos[?p], 75 + 180 Sin[?p]},
 {(75 Sqrt[3] + 420 Cos[?2] + 180 Cos[?p]) (75 Sqrt[3] + 420 Cos[?2] + 460 Cos[?3] + 180 Cos[?p]),
  (75 + 420 Sin[?2] + 180 Sin[?p]) (75 + 420 Sin[?2] + 460 Sin[?3] + 180 Sin[?p])}}
*)

What do you mean by "each of the combinations of Theta2 and Theta3"?

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