Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Struggling with this Python Program

Kausik Kar

New Coder
# QUIZ
#
# Modify the acceleration function so that it returns
# the acceleration vector of the spacecraft.
#
# A sample of how to use the numpy.linalg.norm function
# is given. This computes the length of the vector, and
# it should be the only outside function you need to
# use in your answer.

import numpy

earth_mass = 5.97e24 # kg
moon_mass = 7.35e22 # kg
gravitational_constant = 6.67e-11 # N m2 / kg2

# The origin, or (0,0), is at the center of the earth
# in this example, so it doesn't make any sense to
# set either the moon_position or spaceship_position
# equal to (0,0). Depending on your solution, doing this
# may throw an error! Please note that moon_position and
# spaceship_position are both numpy arrays, and the
# returned value should also be a numpy array.

def acceleration(moon_position, spaceship_position):
vector_to_moon= moon_position-spaceship_position
vector_to_earth= -spaceship_position
return gravitational_constant* (earth_mass/numpy.linalg.norm(vector_to_earth)**3 * vector_to_earth +
moon_mass/numpy.linalg.norm(vector_to_moon)**3 * vector_to_moon)

y= acceleration(10000, 93)
print(y)
 
This seems more like a math question rather then Python, Do they provide any other information as if we knew how to get the answer we could use python to program it.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom