시작하기무료로 시작하기

Absolute value

Previously we fit a straight line to your run times. Now you want to examine how far the values of your run times were from the predictions of the straight-line fit. A common way to do this is by using the absolute difference between the values.

You need to write a function that can calculate the absolute values so you can perform this analysis.

The array of residuals between the straight line and your run times is available in your environment as residuals.

이 연습은 강의의 일부입니다

Introduction to Julia

강의 보기

연습 안내

  • Begin a function named absolute(), which takes a single input value of x.
  • In the function's body, write an if-statement so the function will return x if x>=0 and will return -x otherwise.
  • Use the function to calculate and print the absolute value of each element of the residuals array.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Begin the absolute function
____
	# Write an if-statement to return absolute value of x
	if ____
    	____
    else
    	____
    end
end

# Use the function on residuals
println(____(____))
코드 편집 및 실행