I define a function called VoutCoin:
VoutCoin[Mut_, \[Omega]_, Lc_, Rc_] =
ComplexExpand[Abs[I1coin* (j \[Omega] L1 + (j \[Omega] Mut)^2/(j \[Omega] Lc + Rc))]] /. values
I have the suffixes and the values defined:
M = 10^6;
k = 10^3;
m = 10^-3;
u = 10^-6;
n = 10^-9;
pf = 10^-12;
values = {
R1 -> 180,
C1 -> 9.4 n,
L1 -> 1.7 m,
Vin -> LaplaceTransform[Cos[2*\[Pi]*138 k*t - \[Pi]], t, s]
};
j = I;
s = j*\[Omega];
if I invoke the function as defined above with the following arguments, I get:
In[1030]:= VoutCoin[.5, 2*\[Pi]*10 k, 10 u, .1]
Out[1030]= {0. + 8.40133*10^-8 I}
if I remove the ComplexExpand preceding the Abs in the function, I get:
VoutCoin[Mut_, \[Omega]_, Lc_, Rc_] = Abs[I1coin* (j \[Omega] L1 + (j \[Omega] Mut)^2/(j \[Omega] Lc + Rc))] /. values // Simplify
In[1095]:= VoutCoin[.5, 2*\[Pi]*10 k, 10 u, .1]
Out[1095]= {8.40133*10^-8}
What is going on? Why would ComplexExpand[Abs[]] return a complex numnber?
In case anyone wants plugs this into Mathematica, I'm including I1coin below
In[1092]:= I1coin = I1 /. sol1
Out[1092]= {(Vin (Rc + I Lc \[Omega]))/(Mut^2 \[Omega]^2 - (-R1 + I/(C1 \[Omega]) - I L1 \[Omega]) (Rc +
I Lc \[Omega]))}
Thank you in advance for your help....
--------Edit Per Request_----------------------
M = 10^6;
k = 10^3;
m = 10^-3;
u = 10^-6;
n = 10^-9;
pf = 10^-12;
values = {
R1 -> 180,
C1 -> 9.4 n,
L1 -> 1.7 m,
Vin -> LaplaceTransform[Cos[2*\[Pi]*138 k*t - \[Pi]], t, s]
};
j = I;
s = j*\[Omega];
eq1 = Vin - I1 (R1 + 1/(j \[Omega] C1) + j \[Omega] L1) -j \[Omega] Mut I2 == 0;
eq2 = I2 (j \[Omega] Lc + Rc) + j \[Omega] Mut I1 == 0;
sol1 = Solve[eq1 && eq2, {I1, I2}]
I1coin = I1 /. sol1
VoutCoin[Mut_, \[Omega]_, Lc_, Rc_] = ComplexExpand[Abs[I1coin* (j \[Omega] L1 + (j \[Omega] Mut)^2/(j \[Omega] Lc + Rc))]] /. values // Simplify
In[1159]:= VoutCoin[.5, 2*\[Pi]*10 k, 10 u, .1]
Out[1159]= {0. + 8.40133*10^-8 I}
Question is about result out[1159] --- I don't understand why Mathematica returns a complex number for a magnitude. It seems to happen when I precede Abs with ComplexExpand
s
when I run your code. Are you sure you included all definitions? $\endgroup$CopmlexExpand
assumes all variables are real. If they're not you'll get unexpected errors. check outComplexExpand[Abs[t]] /. t -> I
$\endgroup$I
inside theComplexExpand
; it is simply changing it in the result of the evaluation. For injection, you could try:With[{t = I}, ComplexExpand[Abs[t]]]
, which returns $1$, as I would expect. $\endgroup$=
and not:=
which means that the value is precacluated assumingI1coin
is real. then you probably inject a non-real number.sol1
is not defined in your question so it's hard to tell. It would be easier if you provided one contiguous block of code with all definitions that produces the error. $\endgroup$