Why is my code not working?

1 view (last 30 days)
Michael Vaughan
Michael Vaughan on 26 Sep 2020
Answered: Jim Riggs on 26 Sep 2020
I want the following script to calculate:
function f = CJ(N,k)
syms t
% compute the running sum
running_sum = 0;
for j = -(N-1)/2:(N-1)/2
running_sum = running_sum + t^(4*j^2*k+2*j*k)*t^(4*j+1)-t^(4*j^2*k-2*j*k)*t^(4*j-1);
% final value
f = (1/(t-t^(-1))*running_sum
Here is what happens when I try to run the program:
>> CJ(3,2)
Error: File: CJ.m Line: 10 Column: 34
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
thanks for your help

Answers (1)

Jim Riggs
Jim Riggs on 26 Sep 2020
Not entirely sure if this is the reference in the error message, but this line has unballanced parentheses:
f = (1/(t-t^(-1))*running_sum

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!