"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
Walter Roberson
2019년 9월 1일
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.
James Agerton
2019년 9월 1일
Walter Roberson
2019년 9월 1일
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
답변 (0개)
커뮤니티
더 많은 답변 보기: Power Electronics Community
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!