Question

In: Computer Science

Using Python Suppose a robot starts at the origin and must reach a target point P...

Using Python Suppose a robot starts at the origin and must reach a target point P in the first quadrant of the Cartesian plane. The robot initially moves in a straight line to an intermediate point (x, y) and then turns and travels along a straight line towards the target P. The robot can move anywhere in the first quadrant and along the horizontal and vertical axes except for a circle centered at the point C with radius r.

(a) Determine an objective whose minimum would describe an optimal route from the origin to the target.

(b) Using your code from the first two problems or by implementing an alternative method, write a function that minimizes the objective function. This function should input a target point, P, and the center and radius of the excluded circle and return the optimal intermediate point. Additionally, your code should plot the objective function over a meaningful range of x and y values as well as a plot of the optimal path from the origin to the target point and the excluded circle.

(c) Solve the minimization problem for the following parameters: 1. P = (5, 3), C = (2, 2), r = 1. 2. P = (2, 4), C = (2, 2), r = 1. 3. P = (3, 3), C = (2, 2), r = 1.

Solutions

Expert Solution

1.

def min_path(p1, p2):

  

# dx is total horizontal

# distance to be covered

dx = abs(p1[0] - p2[0])

  

# dy is total vertical

# distance to be covered

dy = abs(p1[1] - p2[1])

  

# required answer is

# maximum of these two

return max(dx, dy)

  

# Function to return the minimum steps

def coverPoints(sequence, size):

stepCount = 0

# finding steps for each

# consecutive poin the sequence

for i in range(size-1):

stepCount += min_path(sequence[i],sequence[i + 1])

return stepCount

# Driver code

# arr stores sequence of points

# that are to be visited

arr = [[4, 6] ,[ 1, 2 ], [ 4, 5] , [ 10, 12]] //here take your inputs as suggested in program

n = len(arr)

print(coverPoints(arr, n))

2.

def circle_equation(x1, y1, r):

a = -2 * x1;

  

b = -2 * y1;

  

c = (r * r) - (x1 * x1) - (y1 * y1);

  

# Printing result

print("x^2 + (", a, "x) + ", end = "");

print("y^2 + (", b, "y) = ", end = "");

print(c, ".");

  

# Driver code

x1 = 2;  

y1 = -3;  

r = 8;

circle_equation(x1, y1, r);

  


Related Solutions

Replication of the E. coli chromosome starts at a particular point, the origin of chromosomal replication...
Replication of the E. coli chromosome starts at a particular point, the origin of chromosomal replication (oriC) and proceeds bidirectionally around the circular chromosome. A. Describe how the strands at oriC are separated to allow replication of the chromosome. B. Once the replication is initiated the process of bidirectional semi-discontinuous DNA replication occurs. Describe this process.
A point on a circle with a diameter of 10m starts at an upright position P...
A point on a circle with a diameter of 10m starts at an upright position P at (0,r) and moves clockwise with an acceleration .6m/s^2 . When t=7 : -Find position -Find velocity -Find acceleration relative velocity
Two sources emit electromagnetic waves that are coherent and in phase. To reach point P, the...
Two sources emit electromagnetic waves that are coherent and in phase. To reach point P, the waves from the first source travel 10 m, and the waves from the second source have travel 15 m. What is the maximum possible wavelength for the waves to have constructive interference at point P?
Point P is located at the origin of a coordinate plane. Object A of charge -1e-9...
Point P is located at the origin of a coordinate plane. Object A of charge -1e-9 C is located on the x-axis of a coordinate plane at x = 0.2 m. Object B of charge 5e-9 C is located on the y-axis of a coordinate plane at y = 0.3 m. Calculate the direction (angle formed with the positive x-axis) of the net electric field at point P due to objects A and B. (1 point) 91.382° -65.772° 125.651° 114.228°...
Suppose a photon starts at the point (−12, 9) along the vector <−4, −3> towards a...
Suppose a photon starts at the point (−12, 9) along the vector <−4, −3> towards a mirror lying on the x-axis (the line y = 0). a) Find a vector function r(t) that describes the path of the photon as it travels towards the mirror. b) Find the value of t0 and the coordinates of the point (x0, y0) where the photon hits the mirror. c) Find the velocity vector r 0 (t0) of the photon when it hits the...
Suppose the economy starts at point 1 in the aggregate supply–aggregate demand (AS-AD) graph and at...
Suppose the economy starts at point 1 in the aggregate supply–aggregate demand (AS-AD) graph and at point A on the Phillips curve graph. Points 2 and 3 start out stacked on point 1, but they will need to be moved to the proper locations that reflect steps 2 and 3 described below. Likewise for points B and C. The AS-AD graph reflects two aggregate demand curves (AD1 and AD2), the long-run aggregate supply curve (LAS) and two short-run aggregate supply...
Suppose a uniformly charged (with a linear charge density z) wire starts at point 0 and...
Suppose a uniformly charged (with a linear charge density z) wire starts at point 0 and rises vertically along the positive y axis to a length z. A) Determine the x-component of the electric field Ex at point (x,0). That is, calculate E? near one end of a long wire, in the plane perpendicular to the wire. Express your answer in terms of the variables l, z, x, and appropriate constants. B) Determine the y-components of the electric field Ey...
Create a python code that calculates fixed point iteration method using a for loop.
Create a python code that calculates fixed point iteration method using a for loop.
Using Python #Write a function called after_second that accepts two #arguments: a target string to search,...
Using Python #Write a function called after_second that accepts two #arguments: a target string to search, and string to search #for. The function should return everything in the first #string *after* the *second* occurrence of the search term. #You can assume there will always be at least two #occurrences of the search term in the first string. # #For example: # after_second("11223344554321", "3") -> 44554321 # #The search term "3" appears at indices 4 and 5. So, this #returns everything...
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT