Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This also relates to Computer Science Problem 1: Vector Operations Now that you understand the basics, let's write your own program. We will start with

This also relates to Computer Science
image text in transcribed
image text in transcribed
image text in transcribed
Problem 1: Vector Operations Now that you understand the basics, let's write your own program. We will start with a simple one that adds three vectors together, as you might remember from the treasure hunt problem. To do this, we need to introduce arrays. An array is a variable type that is like a matrix of any dimension and size we wish. For our vector purposes, we will focus on 1x3 arrays, containing one row and three columns. Arrays can contain any variable type within them, so we could have an array of integers, floating points, strings, or even arrays Floating points will suffice for our needs. Arrays are not included in the base module of Python, so we need to include them by importing an additional module. Python is an open-source programming language, so anyone with the inclination can modify or write new Python code instructions and package them into modules. These modules can be called upon by a program, and as long as the computer has the necessary module installed, the program will access the additional functions correctly. The module that includes arrays and array operations is called NumPy. At the beginning of our program, we should include the following statement: import numpy Any time we want to define an array, we need to tell the program to look in numpy for the array code. So the statement to define a new array would look like this: MyArray numpy.array(1,2,3) The benefit of arrays is that we can add and subtract just as we would numbers, so given two arrays Array1 and Array2, the following operation is valid: Array3 Array1 + Array2 First, define nine floating point variables that will serve as the components for your arrays, naming these a1, b2, etc. Also define three 3x1 vector arrays using these variables (A [a1,a2,a3], for example). Then define a function VectorAdd similar to the Add function above that inputs three vectors and outputs the result as the return line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions