Skip to main content
Commonmark migration
Source Link

#Octave, 27 23 bytes

Octave, 27 23 bytes

@(x,y)sum(z=x:y)^2-z*z'

Creates an anonymous function named ans which accepts two inputs: ans(lower, upper)

Online Demo

Explanation

Creates a row vector from x to y (inclusive) and stores it in z. We then sum all the elements using sum and square it (^2). To compute the sum of the squares, we perform matrix multplication between the row-vector and it's transpose. This will effectively square each element and sum up the result. We then subtract the two.

#Octave, 27 23 bytes

@(x,y)sum(z=x:y)^2-z*z'

Creates an anonymous function named ans which accepts two inputs: ans(lower, upper)

Online Demo

Explanation

Creates a row vector from x to y (inclusive) and stores it in z. We then sum all the elements using sum and square it (^2). To compute the sum of the squares, we perform matrix multplication between the row-vector and it's transpose. This will effectively square each element and sum up the result. We then subtract the two.

Octave, 27 23 bytes

@(x,y)sum(z=x:y)^2-z*z'

Creates an anonymous function named ans which accepts two inputs: ans(lower, upper)

Online Demo

Explanation

Creates a row vector from x to y (inclusive) and stores it in z. We then sum all the elements using sum and square it (^2). To compute the sum of the squares, we perform matrix multplication between the row-vector and it's transpose. This will effectively square each element and sum up the result. We then subtract the two.

added 6 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52

#Octave, 2727 23 bytes

@(x,y)sum(z=x:y)^2-dot(z,z)z*z'

Creates an anonymous function named ans which accepts two inputs: ans(lower, upper)

Online Demo

Explanation

Creates a row vector from x to y (inclusive) and stores it in z. We then sum all the elements using sum and square it (^2). To compute the sum of the squares, we perform matrix multplication between the row-vector and it's transpose. This will effectively square each element and sum up the result. We then subtract the two.

#Octave, 27 bytes

@(x,y)sum(z=x:y)^2-dot(z,z)

Creates an anonymous function named ans which accepts two inputs: ans(lower, upper)

Online Demo

#Octave, 27 23 bytes

@(x,y)sum(z=x:y)^2-z*z'

Creates an anonymous function named ans which accepts two inputs: ans(lower, upper)

Online Demo

Explanation

Creates a row vector from x to y (inclusive) and stores it in z. We then sum all the elements using sum and square it (^2). To compute the sum of the squares, we perform matrix multplication between the row-vector and it's transpose. This will effectively square each element and sum up the result. We then subtract the two.

deleted 9 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52

#Octave, 27 bytes

@(x,y)sum(z=x:y)^2-dot(z,z)

Creates an anonymous function named ans which accepts two inputs: the lower and upper bounds.ans(lower, upper)

Online Demo

#Octave, 27 bytes

@(x,y)sum(z=x:y)^2-dot(z,z)

Creates an anonymous function named ans which accepts two inputs: the lower and upper bounds.

Online Demo

#Octave, 27 bytes

@(x,y)sum(z=x:y)^2-dot(z,z)

Creates an anonymous function named ans which accepts two inputs: ans(lower, upper)

Online Demo

Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52
Loading