"Error: Invalid expression." error when function is called.

function y = I_Zr(angleZ, Z, w, t)
a = 1;
y = Z;
syms n;
while a < length(Z)
y(a) = 20 + symsum(((50/(pi*n))*cos(n*w*t + angleZ(a)))/Z(a), n, [1, inf]);
a=a+1;
end
end
I wrote the above code to try to calculate the current through an RCL circuit I have. I have already calculated the Impedence of the circuit with other functions but this one doesn't run for some reason. I think it might be because I am using symsum incorrectly, or don't understand the equation to some degree. Any help is appreciated.
angleZ and Z are both 1x100 doubles, but when I try to run it through the command window, I get the "Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters." error.

3 Comments

What input are you using for w and t?
Is there a reason you are not including angleZ(end) and Z(end) in your calculation ? Is there a reason you are not using a for loop ?
Which line is the error occuring on?
I used rand() to create angleZ and Z and called
y = I_Zr(angleZ, Z, 2, 5);
without difficulty.
I have forgotten what I knew about this program, could you explain what (end) is?
And there's not a reason to not use a for loop other than that I recognised the syntax for while easier than the for syntax.
I'm trying desperately to both remember how to use Matlab and the equations for RLC circuits.
Z(end) is the last Z. With Z being 1 x 100, it would be Z(100) .
Your code is looping until a < length(Z) and when true it accesses AngleZ(a) and Z(a) . a = 99 works because 99 < 100 so AngleZ(99) and Z(99) would be accessed, but then you increment from 99 to 100, and 100 < 100 is false so you do not access AngleZ(100) or Z(100) and you do not store into y(100) . However you initialized y = Z; so y(100) will be left untouched as Z(100) which might or might not be what you want
for a = 1 : length(Z)
y(a) = 20 + symsum(((50/(pi*n))*cos(n*w*t + angleZ(a)))/Z(a), n, [1, inf]);
end

Sign in to comment.

Answers (0)

Communities

More Answers in the  Power Electronics Control

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2019a

Asked:

on 1 Sep 2019

Commented:

on 1 Sep 2019

Community Treasure Hunt

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

Start Hunting!