Function in Matlab not working correctly : <p>I'm trying to write the following function which computes the sum of the series 1 + x^1 + ... + x^n. I have</p>

<pre><code>function[result] = sumGP(x,n)
if x == 1
    result = n+1;
else
    result = (x^(n+1) - 1)/(x-1);
end

sumGP(1,4)
</code></pre>

<p>If I want to call this function using 'sumGP(1,4)', the output should be '5'. But Matlab is saying 'undefined function of variable 'x'. </p>
