To create a vector of 1/n from 1 to 20 without using a loop in Matlab, you can use vectorization. You can achieve this by dividing 1 by a vector containing the numbers from 1 to 20.
Here's the code:
main.m25 chars3 lines
The n
variable represents a vector containing the numbers from 1 to 20. The ./
operator performs element-wise division between 1
and each element in the vector n
, generating a new vector result
.
This vector result
will contain the values of 1/n from 1 to 20 without using a loop.
gistlibby LogSnag