Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need some help writing up this lab in python (first year engineering course) import math def magnitude(x,y): (float,float) -> float Function calculate the magnitude

Need some help writing up this lab in python (first year engineering course)

import math

def magnitude(x,y):

"""

(float,float) -> float

Function calculate the magnitude of a 2D vector. The x- and y-components

of the vector are given as input parameters to the function as floats.

The function returns the magnitude of the vector as a float.

The magnitude of a 2D vector can be calculated using the following

equation:

____________

/

magnitude = v x^2 + y^2

where x and y are the x and y components of the vector

>>> magnitude(10.0,25.5)

27.390691849604675

"""

## TODO: YOUR CODE HERE

def phase(x,y):

"""

(float,float) -> float

Function calculates the phase angle of a 2D vector. The x- and y-components

of the vector are given as input parameters to the function as floats.

The function returns the phase angle in radians as a float.

The phase angle of a 2D vector can be calcuated using the following

equation:

phase = atan( y / x )

where atan represents the inverse tangent function and x and y are

the x and y components of the vector

Hint: In Python's math module, there are two functions that can be used to

calculate the inverse tangent. Find the two options in the

documentation here:

https://docs.python.org/3/library/math.html#trigonometric-functions

OR

use the help function to get information for both inverse tangent

functions

>>> import math

>>> help(math.atan)

>>> help(math.atan2)

>>> phase(10.0,25.5)

1.197069506829343

"""

## TODO: YOUR CODE HERE

## TODO: Write your test cases here - MAKE SURE YOU DELETE THESE LINES BEFORE

SUBMITTING

# example

x = 10.0

y = 25.5

mag = magnitude(x,y)

phi = phase(x,y)

print("The magnitude is: ", mag)

print("The phase is: ", phase)

## DELETE EVERYTHING UP TO THIS 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

Students also viewed these Databases questions