MulaiMulai sekarang secara gratis

The Algebra of Vectors

Vectors can be made to make new vectors much in the same way that numbers can.

To add two vectors together in R, simply use the + command.

Vectors can also be scaled via multiplication by a real number (or scalar), using the * command.

Multiplication of two vectors is a trickier topic theoretically, but in R, component-wise multiplication of two vectors is legal and accomplished using the * command.

The vectors x, y, and z have been loaded for you.

Latihan ini adalah bagian dari kursus

Linear Algebra for Data Science in R

Lihat Kursus

Petunjuk latihan

  • Add the vector x to the vector y and print the result.

  • Multiply the vector z by the scalar 2.

  • Multiply the vectors x and y to each other, component-wise, and print the result.

  • Try to add the vector x to the vector z. What happens?

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Add x to y and print
print(x ___ y)

# Multiply z by 2 and print
print(2 ___ z)

# Multiply x and y by each other and print
print(___ ___ y)

# Add x to z, if possible, and print
print(x + ___)
Edit dan Jalankan Kode