Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
image text in transcribed

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

More Books

Students also viewed these Databases questions