Making Vector Addition programmeable

In summary, the speaker wants to create a program for vector addition and subtraction, but is struggling with the math involved. They explain their idea of having the user input vectors with magnitude and angle, and mention needing to use the law of cosines. They ask for help in converting vectors to components and using the law of cosines.
  • #1
KingNothing
881
4
Hello...I really want to make a program that can do vector addition and subtraction, given two or more vectors. The problem is, I'm not sure of the math that would be needed to do it. See, I want the person to be able to enter two or more vectors with a magnitude (length) and angle (with 0 degrees being 'up' and 90 degrees being 'right'). I'm struggling a bit with the actual math that needs to be done. I can do it on paper just fine, because the process of taking a bearing of 1125 degrees and making it 45, etc, things of this nature - is logical. But programs don't understand logic. That's where I hit the roadblock.

I don't think you need to know any programming whatsoever to answer this (granted you know the answer)...just be able to say things like:

1. Sbtract angle a from angle b, save to variable a.

etcetera. I'd a little fuzzy on the part of figuring out how to "get two vectors together" to be prepared to use the law of cosines and whatnot to figure the resultant out. Can you help?
 
Mathematics news on Phys.org
  • #2
Convert each of the vectors to components in some basis, then add the components.

- Warren
 
  • #3


Sure, I'd be happy to help with your project! Vector addition and subtraction can definitely be programmed, and it's a great way to practice your math and programming skills. Here are a few tips to get you started:

1. First, you'll need to understand the basics of vectors and vector operations. This includes understanding how to represent a vector using magnitude and direction (angle), how to add and subtract vectors, and how to use the law of cosines to find the resultant vector.

2. Once you have a solid understanding of vector operations, you can start thinking about how to translate these operations into code. This will involve breaking down each step of the process into smaller, more manageable tasks. For example, to add two vectors, you'll need to first convert their magnitudes and angles into x and y components, then add the x components together and the y components together, and finally convert the resulting x and y components back into a magnitude and angle.

3. It may be helpful to sketch out the steps on paper first, to make sure you have a clear understanding of what needs to be done before diving into the code. You can also use pseudocode (a simplified version of code) to plan out your program before writing actual code.

4. As for the specific steps you mentioned, here are a few suggestions:

- To subtract angle a from angle b, you can use the formula: result = b - a. Keep in mind that angles in programming are usually measured in radians, so you may need to convert from degrees to radians first.
- To "get two vectors together", you'll need to prompt the user to input the magnitude and angle for each vector. Then, you can store these values in variables and use them in your calculations.
- To use the law of cosines to find the resultant vector, you'll need to first convert the magnitudes and angles of the two vectors into x and y components, then use the law of cosines formula: c^2 = a^2 + b^2 - 2ab*cos(C), where c is the magnitude of the resultant vector, a and b are the magnitudes of the two vectors, and C is the angle between them. Once you have the magnitude of the resultant, you can use inverse trigonometric functions to find the angle.

I hope this helps get you started on your project! Remember to break down the problem into smaller, manageable steps and don't be afraid to ask for
 

Related to Making Vector Addition programmeable

1. What is vector addition and why is it important?

Vector addition is a mathematical operation that combines two or more vectors to create a new vector. It is important in many fields such as physics, engineering, and computer graphics, as it allows for the representation and manipulation of complex physical quantities and movements.

2. How can vector addition be made programmable?

Vector addition can be made programmable by writing a code or algorithm that takes in the values of the vectors and performs the addition operation. This code can be written in a programming language such as C++, Java, or Python.

3. What are the benefits of having a programmable vector addition?

Having a programmable vector addition allows for quicker and more accurate calculations, as well as the ability to perform the operation on a large number of vectors. This can save time and effort, especially in complex calculations.

4. What are some challenges in creating a programmable vector addition?

Some challenges in creating a programmable vector addition include understanding the mathematical concepts behind vector addition, writing efficient and error-free code, and ensuring compatibility with different programming languages and systems.

5. Can vector addition be programmed in any language?

Yes, vector addition can be programmed in any language as long as the language supports mathematical operations and has the necessary tools for handling vectors and arrays. However, some languages may be more suitable for vector addition than others.

Similar threads

  • General Math
Replies
11
Views
1K
  • General Math
Replies
1
Views
1K
Replies
33
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
160
  • General Math
Replies
4
Views
2K
Replies
10
Views
774
Replies
2
Views
1K
  • General Math
Replies
7
Views
2K
  • Precalculus Mathematics Homework Help
Replies
3
Views
2K
  • General Math
Replies
4
Views
8K
Back
Top