Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Can you please alter the below code to answer these two part questions on python, First part of the question asks to compute the average,

Can you please alter the below code to answer these two part questions on python,

First part of the question asks to compute the average, per-particle kinetic energy for collections of 128, 256, 512, 1024, 2048, 4096, 8192, 16384 and 32768 point mass particles. Plot the average per-particle kinetic energy vs. the log base 2 of the number of particles.

Part B aks to compute the average per-particle elastic potential energy using an equilibrium distance from the origin of 1.4142, for collections of 128, 256, 512, 1024, 2048, 4096, 8192, 16384 and 32768 point mass particles. Plot the average per-particle kinetic energy vs. the log base 2 of the number of particles.

Below is the code:-

import math import random import string import secrets

class PointMass2D(object): """Class defines point masses in 2D, along with attributes of point masses and basic behaviors. Class requires the following imports prior to invocation: import math import random import string import secrets """ def __init__(self): #Position (xcoord,ycoord) is randomly assigned on the #square domain ([-10.0,10.0),[-10.0,10.0)) self.coordx = 20.0*random.random() - 10.0 #interp: meters self.coordy = 20.0*random.random() - 10.0 #interp: meters self.dist_from_origin = math.sqrt(self.coordx**2 + self.coordy**2) #Notional, randomly assigned mass in the range [0.0,10.0) self.mass = 10.0*random.random() #interp: kilograms #Notional, randomly assigned velocity in the range [0.0,5.0) self.velx = 5.0*random.random() #interp: m/s self.vely = 5.0*random.random() #interp: m/s self.momentumx = self.mass * self.velx self.momentumy = self.mass * self.vely self.kinetic_energy = 0.5*self.mass*(self.velx**2 + self.vely**2) #Randomly generate string name (10 capital letters and numbers) #There are 3,656,158,440,062,976 unique names possible self.name = ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(10))

def distance_to_other_pointmass(self, other_pointmass): dist_to_other_pointmass = math.sqrt((self.coordx - other_pointmass.coordx)**2 + (self.coordy - other_pointmass.coordy)**2) return dist_to_other_pointmass def relocate_to_origin(self): self.coordx = 0.0 self.coordy = 0.0 def relocate_randomly_inside_domain(self): self.coordx = 20.0*random.random() - 10.0 self.coordy = 20.0*random.random() - 10.0

#Total number of point masses to create: total_point_masses = 500

#Create a list of 500 point masses: points_lst = [PointMass2D() for x in range(total_point_masses)]

#Compute the total kinetic energy of the 500 point masses: total_kinetic_energy = sum([x.kinetic_energy for x in points_lst])

#Compute the total elastic potential energy of the #500 point masses, assuming that the equilibrium #distance from the origin is equal to equil_dist_to_origin: equil_dist_to_origin = 1.4142 total_elastic_potential_energy = sum([-1.0*(x.dist_from_origin - equil_dist_to_origin)**2 for x in points_lst])

print(' The total kinetic energy of the assembly of ',total_point_masses, ' point masses is (in joules): ',total_kinetic_energy)

print(' The total elastic potential energy of the assembly of ',total_point_masses, ' point masses is (in joules): ',total_elastic_potential_energy)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Question

A 300N F 30% d 2 m Answered: 1 week ago

Answered: 1 week ago