This is the sum I'm trying to use:
1 + r^2 + r^4 + r^6 + … + r^n
If n isn't even, I'm supposed to display an error.
Here's my code:
function [sum] = series(r,n)sum = 1;if mod(n,2) == 0 for i=2:n sum = sum + r.^i; endelse disp('Error!'); endend
Keeps returning the wrong value. What's wrong with my code?
Best Answer