Invalid expression, check for mismatched delimiters. Trying to form a matrix using brackets.

12 Ansichten (letzte 30 Tage)
I keep getting the error message: >> abc2sc
File: abc2sc.m Line: 21 Column: 28
Invalid expression. When calling a function or indexing a variable, use
parentheses. Otherwise, check for mismatched delimiters.
Here is my preliminary code.
function [symcomp] = abc2sc(fabc)
rankfabc=length(fabc(1,:));
if rankfabc == 2
mag=fabc(:,1); ang=pi/180*fabc(:,2);
fabcr=mag.(cos(ang)+jsin(ang));
elseif rankfabc ==1
fabcr=fabc;
else
fprintf('\n Three phasors must be expressed in a one column array in rectangular complex form \n')
fprintf(' or in a two column array in polar form, with 1st column magnitude & 2nd column \n')
fprintf(' phase angle in degree. \n')
return, end
a=cos(2*pi/3)+jsin(2*pi/3);
A = [1 1 1; 1 a^2 a; 1 a a^2];
fa012=inv(A)*fabcr;
symcomp= fa012;
%scpolar = [abs(fa012) 180/piangle(fa012)];
%fprintf(' \n Symmetrical components \n')
%fprintf(' Magnitude Angle Deg.\n')
%disp(scpolar)
fabc0=fa012(1) [ 1; 1; 1 ];
fabc1=fa012(2) [ 1; a^2; a ];
fabc2=fa012(3) [ 1; a; a^2 ];
end

Akzeptierte Antwort

Jan
Jan am 9 Mai 2022
Bearbeitet: Jan am 9 Mai 2022
What is the meaning of this line:
fabcr=mag.(cos(ang)+jsin(ang));
This treats "mag" as a struct and tries to interprete "cos(ang)+jsin(ang)" as field name. What is "jsin"? Maybe you mean:
fabcr = mag .* (cos(ang) + 1j * sin(ang));
The error appears in these lines, I guess (by the way, if you post the complete error message, the readers would see, which line is failing):
fabc0=fa012(1) [ 1; 1; 1 ];
fabc1=fa012(2) [ 1; a^2; a ];
fabc2=fa012(3) [ 1; a; a^2 ];
What is the purpose of these lines? Did you forget some * characters for a multiplication? The output fabc0/1/2 is not used anywhere, so whay not simply omitting these lines?
This looks suspicious also:
a=cos(2*pi/3)+jsin(2*pi/3);
Did you really create a function called jsin()?
By the way, prefer the backslash operator instead of calling inv(). See: inv

Weitere Antworten (0)

Kategorien

Mehr zu Particle & Nuclear Physics finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by