Question: import matplotlib.pyplot as plt import math import astropy.coordinates #Takes a 3 D vector, and returns a tuple of the x , y , and z

import matplotlib.pyplot as plt
import math
import astropy.coordinates
#Takes a 3D vector, and returns a tuple of the x, y, and z components
def spherical_to_components(magnitude, bearing, trajectory):
return astropy.coordinates.spherical_to_cartesian(magnitude, math.radians(trajectory), math.radians(bearing))
#Takes the x, y, and z components of a 3D vector, and returns a tuple of magnitude, bearing, and trajectory
def components_to_spherical(x, y, z):
magnitude, trajectory, bearing = astropy.coordinates.cartesian_to_spherical(x, y, z)
return magnitude, math.degrees(bearing.to_value()), math.degrees(trajectory.to_value())
#Takes two 3D vectors (each specified by magnitude, bearing, and trajectory) and returns a
#tuple representing the sum of the two vectors
def add_spherical_vectors(magnitude1, bearing1, trajectory1, magnitude2, bearing2, trajectory2):
x1, y1, z1= spherical_to_components(magnitude1, bearing1, trajectory1)
x2, y2, z2= spherical_to_components(magnitude2, bearing2, trajectory2)
return components_to_spherical(x1+ x2, y1+ y2, z1+ z=============================================start with the code provided above and please use this approach below======== import matplotlib.pyplot as plt
class SimpleDTSim:
def __init__(self):
# You might want to initialize the simulation here, but that means that you will initialize when the
# object is created, rather than on every simulation run
self.x =0
self.a =0
self.result =[]
def initialize(self, starting_x, a):
self.x = starting_x
self.a = a
self.result =[self.x]
def observe(self):
self.result.append(self.x)
def update(self):
self.x = self.a * self.x
def runsim(self, x, a, steps):
self.initialize(x, a)
for t in range(steps):
self.update()
self.observe()
plt.plot(self.result)
plt.show()
if __name__=='__main__':
sim = SimpleDTSim()
sim.runsim(1,1.1,30)
 import matplotlib.pyplot as plt import math import astropy.coordinates #Takes a 3D

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!