{"id":37927,"date":"2016-10-03T19:34:30","date_gmt":"2016-10-04T00:34:30","guid":{"rendered":"http:\/\/hectormtzblog.wordpress.com\/?p=449"},"modified":"2016-10-03T19:34:30","modified_gmt":"2016-10-04T00:34:30","slug":"sum-of-vectors-program","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/sum-of-vectors-program\/","title":{"rendered":"Sum of vectors program"},"content":{"rendered":"<p class=\"syndicated-attribution\"><em> --Originally published at <a href=\"https:\/\/hectormtzblog.wordpress.com\/2016\/10\/03\/sum-of-vectors-program\/\"><a href=\"https:\/\/hectormtzblog.wordpress.com\">Hector Martinez Alcantara<\/a><\/a><\/em><br \/><\/p>\n<p class=\"tw-data-text tw-ta tw-text-medium\" dir=\"ltr\">Today I finished a program that can tell you the sum of three, or as many vectors as you want and the vector that balance\u00a0the system.<\/p>\n<p class=\"tw-data-text tw-ta tw-text-medium\" dir=\"ltr\">There is a menu that shows two options.<\/p>\n<p class=\"tw-data-text tw-ta tw-text-medium\" dir=\"ltr\">In the case A you type 3 forces with their angles, and then the program shows the sum of components in X, components in Y, the\u00a0resulting vector with its angle, and the vector with the angle that balances the system.<\/p>\n<p class=\"tw-data-text tw-ta tw-text-medium\" dir=\"ltr\">In the case B you type how many forces you want, then you type the forces with their angles, and then the program shows the sum of components in X, components in Y, the\u00a0resulting vector with its angle, and the vector with the angle that balances the system.<\/p>\n<pre id=\"tw-target-text\" class=\"tw-data-text tw-ta tw-text-medium\">import math\n#------------------SHOWS THE VECTOR AND IT'S COMPONENTS-----------------\ndef Vector(compx,compy):\n magnr=math.hypot(float(compx), float(compy))\n print(\"\\nSumatoria de componentes en X \" + str(compx))\n print(\"Sumatoria de componentes en Y \" + str(compy))\n print(\"\\nVector Resultante:\")\n if compx&lt;0.0 and compy&gt;0.0:\n print(\"Segundo sector\")\n angr=math.degrees(math.atan(compy\/compx)) + 180.0\n elif compx&lt;0.0 and compy&lt;0.0:\n print(\"Tercer sector\")\n angr=math.degrees(math.atan(compy\/compx))+ 180.0\n elif compx&gt;0.0 and compy&lt;0.0:\n print(\"Cuarto sector\")\n angr=360+math.degrees(math.atan(compy\/compx))\n else:\n print(\"Primer sector\")\n angr=math.degrees(math.atan(compy\/compx))\n print(\"La magnitud del vector resultante es \"+ str(magnr) +\"N\")\n print(\"El angulo del vector resultante es \"+ str(angr) +\"\u00b0 del eje +x\")\n print(\"\\nVector Complementario:\")\n if compx&lt;0.0 and compy&gt;0.0:\n print(\"Cuarto sector\")\n angr= angr + 180.0\n elif compx&lt;0.0 and compy&lt;0.0:\n print(\"Primer sector\")\n angr= angr - 180\n elif compx&gt;0.0 and compy&lt;0.0:\n print(\"Segundo sector\")\n angr= angr - 180.0\n else:\n print(\"Tercer sector\")\n angr= angr + 180.0\n print(\"La magnitud del vector complementario es \"+ str(magnr) +\"N\")\n print(\"El angulo del vector complementario es \"+ str(angr) +\"\u00b0 del eje +x\")\n#--------------MAIN PROGRAM--------------------------------\ny=0\nwhile y!=1:\n print(\"\\nCasos:\")\n print(\"A) Tres fuerzas, encontrar la fuerza <div class=\"post-limited-image\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/hectormtzblog.wordpress.com\/449\/\" \/><\/div>\n<div class=\"post-limited-image\"><img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=hectormtzblog.wordpress.com&#038;blog=115238241&%23038;post=449&%23038;subd=hectormtzblog&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/><\/div><!--more--> pone en equilibrio el sistema\")\n print(\"B) Determine cuantas y cuales fuerzas actuan sobre el sistema, y cual lo pone en equilibrio\\n\")\n op=input()\n op=op.lower()\n#---------------CASE A-------------------------------------\n if op=='a':\n magn1=input(\"Ingrese magnitud de fuerza 1\\n\")\n ang1=input(\"Ingrese angulo de fuerza 1 con respecto al eje +x\\n\")\n magn2=input(\"Ingrese magnitud de fuerza 2\\n\")\n ang2=input(\"Ingrese angulo de fuerza 2 con respecto al eje +x\\n\")\n magn3=input(\"Ingrese magnitud de fuerza 3\\n\")\n ang3=input(\"Ingrese angulo de fuerza 3 con respecto al eje +x\\n\")\n compx=(float(magn1)*math.cos(math.radians(float(ang1))))+(float(magn2)*math.cos(math.radians(float(ang2))))+(float(magn3)*math.cos(math.radians(float(ang3))))\n compy=(float(magn1)*math.sin(math.radians(float(ang1))))+(float(magn2)*math.sin(math.radians(float(ang2))))+(float(magn3)*math.sin(math.radians(float(ang3))))\n Vector(compx,compy)\n \n#---------------CASE B-------------------------------------\n elif op=='b':\n cant=input(\"\u00bfCu\u00e1ntas fuerzas actuan sobre el sistema?\\n\")\n magnitudes=[]\n angulos=[]\n for x in range(int(cant)):\n magn=input(\"Ingrese magnitud de fuerza \" + str(x+1) +\"\\n\")\n ang=input(\"Ingrese angulo de fuerza \" + str(x+1) + \" con respecto al eje +x\\n\")\n magnitudes.append(float(magn))\n angulos.append(float(ang))\n compx=0\n compy=0\n for x in range(int(cant)):\n print(str(x))\n compx=float(compx) + (float(magnitudes[x])*math.cos(math.radians(float(angulos[x]))))\n compy=float(compy) + (float(magnitudes[x])*math.sin(math.radians(float(angulos[x]))))\n Vector(compx,compy)\n \n#---------------NO OPTION-----------------------------------\n else:\n print(\"La opci\u00f3n \"+ op +\" no es una opcion\")<\/pre>\n<p>The function Vector receives the sum of the components in X, Y \u00a0and realize the operations to find the resultant vector and its angle, then it only add 180 degrees to find the vector who balance the system.<\/p>\n<p>Then the program receives an option and convert it to lower, if is &#8216;a&#8217; enter to the case A, and if it&#8217;s &#8216;b&#8217;, enter to the case B, if its none of the other cases, it shows a message who says that&#8217;s not an option.<\/p>\n<p>In the case A I do\u00a0one by one the steps to do the sum of\u00a0vectors, in the case B I ask first, how many forces are in the system, then in a loop I append the magnitude and the angle of the vectors to a list, and in another loop I sum all the components, finally\u00a0I use the function Vector to show the resultant vectors.<\/p>\n<p>And that&#8217;s all, thanks for reading.<\/p>\n<p>&nbsp;<\/p><br \/>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/hectormtzblog.wordpress.com\/449\/\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/hectormtzblog.wordpress.com\/449\/\" \/><\/a> <img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=hectormtzblog.wordpress.com&#038;blog=115238241&%23038;post=449&%23038;subd=hectormtzblog&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/>","protected":false},"excerpt":{"rendered":"<p>&#8211;Originally published at Hector Martinez Alcantara Today I finished a program that can tell you the sum of three, or as many vectors as you want and the vector that balance\u00a0the system. There is a menu that shows two options. In the case A you type 3 forces with their angles, and then the program &hellip; <a href=\"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/sum-of-vectors-program\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Sum of vectors program<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[88,284,89,26,33],"class_list":["post-37927","post","type-post","status-publish","format-standard","hentry","category-blogs","category-syndicated","tag-learninganewlanguage","tag-physics","tag-python3","tag-sin-categoria","tag-tc101"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/37927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/comments?post=37927"}],"version-history":[{"count":1,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/37927\/revisions"}],"predecessor-version":[{"id":37928,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/37927\/revisions\/37928"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media?parent=37927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/categories?post=37927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/tags?post=37927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}