MATLAB: Can’t i plug in a range of values into this equation

dimensionsMATLAB and Simulink Student Suitematrix

"equ" calculates interest growth, with r being the interest rate.
i want to plot a graph for the function "equ" from 0.001 to 0.1
r= linspace(0.001,0.1)
equ = 1000*((1+r)/r)*((1+r)^5 -1)
plot(r, equ)
i keep getting an error message:
"Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power.
Check that the matrix is square and the power is a
scalar. To perform elementwise matrix powers, use
'.^'."
when i do the alterations it suggests i get the wrong value.
what do i do?

Best Answer

The ‘equ’ function needs to use element-wise operations (using the dot operator):
r= linspace(0.001,0.1);
equ = 1000*((1+r)./r).*((1+r).^5 -1);
plot(r, equ)
See the documentation on Array vs. Matrix Operations for an extended discussion.