Answer to Question #194794 in Python for ritik

Question #194794

Given the line

y= 3x+ 15

, and the points a = (1,0) and b= (9,0), which point 

has the smallest squared error from the line?


1
Expert's answer
2021-05-18T05:39:56-0400
def sq_err(p):
    x, y = p
    y_actual = 3*x + 15
    return (y-y_actual)**2


def main():
    a = (1, 0)
    b = (9, 0)
    err_a = sq_err(a)
    err_b = sq_err(b)

    if err_a < err_b:
        print(f'Point {a} has square error {err_a} from the line, and it\'s the smallest')
    elif err_b < err_a:
        print(f'Point {b} has square error {err_b} from the line, and it\'s the smallest')
    else:
        print(f'Points {a} and {b} have the same square errors {err_a} from the line')


main()


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS