Complex number error (number will be an array)

1 visualización (últimos 30 días)
Jaemin Kim
Jaemin Kim el 28 de Mzo. de 2020
Comentada: Jaemin Kim el 28 de Mzo. de 2020
The values in last line is definetely a number(complex).
But, if I put [number], it will be an array(1,2). (Example1 is a number, Example2 is an array)
Why is this happend? How could I figure out?
clear
clc
close all
%%constant
c = 299792458;
f = 34.3e9;
mu0 = 4*pi*1e-7;
eps0 = 1/(c^2*mu0);
eps_sub = 11.256;
n_sub = sqrt(eps_sub);
mu_sub = 1;
eps_sub = 11.256;
lambda0 = c/f;
beta0 = 2*pi/lambda0;
beta_sub = beta0*n_sub;
alpha_sub = 0.01*beta_sub;
gamma = alpha_sub + 1i*beta_sub;
Z_sub = sqrt((mu0*mu_sub)/(eps0*eps_sub));
eta0 = sqrt(mu0/eps0);
d = lambda0/14;
theta = linspace(-1.5*pi, 2.5*pi,10);
w = 2*pi*f;
i=1;
%% equation
ABCD_TL = [cos(beta_sub*d), 1i*Z_sub*sin(beta_sub*d) ; 1i*sin(beta_sub*d)/Z_sub, cos(beta_sub*d)];
S11 = 0;
S12 = exp(1i*theta(i));
S22 = 0;
S21 = exp(1i*theta(i));
A_S = ((1+S11)*(1-S22) + S12*S21)/(2*S21);
B_S = eta0*((1+S11)*(1+S22) - S12*S21)/(2*S21);
C_S = (1/eta0)*((1-S11)*(1-S22) - S12*S21)/(2*S21);
D_S = ((1-S11)*(1+S22) + S12*S21)/(2*S21);
A=ABCD_TL(1,1);
B=ABCD_TL(1,2);
C=ABCD_TL(2,1);
D=ABCD_TL(2,2);
LC = [1;1;1;1];
Example1 = A^2 + B*C + A*B*(1/(1i*(w*LC(3) - 1/(w*LC(4))))) +(1/(1i*(w*LC(1) - 1/(w*LC(2)))))*(A*B + B^2*(1/(1i*(w*LC(3) - 1/(w*LC(4))))) + B*D) - A_S
Example2 = [A^2 + B*C + A*B*(1/(1i*(w*LC(3) - 1/(w*LC(4))))) +(1/(1i*(w*LC(1) - 1/(w*LC(2)))))*(A*B + B^2*(1/(1i*(w*LC(3) - 1/(w*LC(4))))) + B*D) - A_S]

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Mzo. de 2020
Inside of [], anywhere that you have an element, followed by whitespace, followed by - or + followed immediately by an element without any space, then the whitespace will be considered to be separating elements of a vector. For example,
[1 -2 +3]
is the same as
[1, -2, +3]
and that is not the same as
1 -2 +3
outside of [] -- outside of [] the whitespace is mostly ignored so it would be treated the same as 1-2+3
In particular you have a stretch with whitespace followed by +(1/(1i*(w*LC(1) and that is being treated as unary +
To get around the problem, put a space after the +
Example2 = [A^2 + B*C + A*B*(1/(1i*(w*LC(3) - 1/(w*LC(4))))) + (1/(1i*(w*LC(1) - 1/(w*LC(2)))))*(A*B + B^2*(1/(1i*(w*LC(3) - 1/(w*LC(4))))) + B*D) - A_S]
just like you had in all of the other + and - in the line.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by