BaşlayınÜcretsiz Başlayın

Euclidean distance from 0

For your second function, you will compute the distance from 0 to a point in a 2D space.

Unless otherwise noted, assume that Rcpp is loaded in your workspace.

Bu egzersiz

Optimizing R Code with Rcpp

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

Write a C++ function euclidean_distance() that takes two arguments x and y (both double) and returns another double that is the euclidian distance between (0, 0) and (x, y) points.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Define the function euclidean_distance()
cppFunction('
  ___ euclidean_distance(___, ___) {
    ___ sqrt(x*x + y*y) ;
  }
')

# Calculate the euclidean distance
euclidean_distance(1.5, 2.5)
Kodu Düzenle ve Çalıştır