Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python without print Write the function lengthSegment(x1, y1, z1, x2, y2,

ID: 3742958 • Letter: U

Question

Using Python without print

Write the function lengthSegment(x1, y1, z1, x2, y2, z2) that takes 6 float values, repre- senting the Cartesian coordinates of the endpoints of a line segment in 3-space, and returns the Euclidean length of this line segment.
Euclidean distance in 3-space. The Euclidean distance formula that you explored in the previous problem (distOrigin) generalizes to higher dimensions elegantly: research this idea here. Foreshadowing of future Python syntax. It is rather ugly to use 6 parameters for this function: wouldn’t it be better to capture a point as a single thing (so gather the three coordinates together), and then gather the 2 points as a single thing (of a different type) representing a line segment? This would allow 1 or 2 parameters rather than 6. We will later see how to gather several related values together in a sequence, container, or class. Given the structure of the Euclidean distance formula, it is also tempting to repeat the same calculation, marching down the coordinates, a foreshadowing of iteration. So this version of this computation is not the final ideal form for clarity and efficiency.

Explanation / Answer

# Using python without print function lengthSegment(x1, y1, z1, x2, y2, z2) that takes 6 float values
#import math;

# Initializing function length segment
list = [x1,y1,z1,x2,y2,z2] //initialising the function length segment
for x1 in range(0,length(list)):
segment (li[i],end=" ")
show segment("s")

# using the segment takes 6 float values
operator.setitem(list,6,)
float(x1,y1,z1,x2,y2,z2);
show segment ("The modified list after setitem() is : ",end="")
for x1 in range(0,length(list))
operator.delitem(list,1)

#The Euclidean distance formula that you explored in the previous problem (distOrigin) generalizes
to higher dimensions elegantly

#example for Euclidean for 3 space:
x = (4, 5, 6);
y = (7, 8, 8);
distance = math.3 space(sum([(x1- z1) ** 2 for x, y,z in zip(x, y, z)]))

# have 32 points in 3 space(x1, y1, z1, x2, y2, z2)
(dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) //representing 2 points of 3 space
a= numberpython.array((x1a ,y1a, z1a))
b = numberpython.array((x2b, y2b, z2b))
#foreshading of future python syntax
length segment = numberpython.linealgorithm.normal(a-b)
from repeat.calculation import length segment
x = (4, 5, 6)
y = (7, 8, 8)
length = distance.euclidean(x, y)
class length
define __initial__(self, x1, y1,z1):
self.x1, self.y1 = x1, y1,z1

define __string__(self):
return "{}, {}".format(self.x2, self.y2, self.z2)

define __neg__(self):
return length(self.x2, -self.y2)

define __add__(self, length segment):
return length(self.x1+length.x2, self.y1+length.y2, self.z1+length.z2)

define __sub__(self,length segment):
return self + length segment

x_min_y = x - y
numberpython.squareroot(numberpython.einsum('x1,y1,z1,x2,y2,z2'), x_min_y, x_min_y)) // computes the length segment of x and y
New_formula_Start_distOrigin = (0+4j) + (0+0j)
New_formula_End_distOrigin = New_formula_Start_distOrigin + (8+0j)

perftplot.show( //using the structure of the Euclidean distance formula,
setup=lambda n: numberpython.random.rand(2, n, 3),
n_range=[2**k for k in range(40)],
kernels=[linealgorithm_norm, scipy_distance, mpl_dist, sqrt_sum, sqrt_einsum], //defining the marching down of coordinates
logx=True,
logy=True,
xlabel='len(x), len(y)'
#tempting to repeat the same calculation, marching down the coordinates, a foreshadowing of iteration
defining distance(pointx, pointy):
distance = np.linealgorithm.norm(pointx - pointy)
return distance
)
Hope you understand and this helps you.All the best

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote