Error using + Complex integer arithmetic is not supported.
56 views (last 30 days)
Show older comments
Why can I get a result when I dont put int64() in front of Ff and put it in front of Zf, but not whe I put it in front of both?
if true
format long
a = 1
b = 3E-7
c = 5E-8
f0 = 4E9
sigma = 0.2
t0 = 0
tmax = 2.*b
f = linspace(1E6,1E10,1000)
t = linspace(t0, tmax,1000)
omega = 2.*pi.*f
omega0 = 2.*pi.*f0
G = -2.*pi.*f.*(pi.*c.^2.*f + sqrt(-1).*b)
D = (((b-(sqrt(-1)).*2.*pi.*c.^2.*f-t0)/(sqrt(2).*c)))
E = (((b-(sqrt(-1)).*2.*pi.*c.^2.*f-tmax)/(sqrt(2).*c)))
Ff = uint64(abs(sqrt(pi/2).*a.*c.*exp(G).*((-sqrt(-1).*(erfi(-sqrt(-1).*D)))-((-sqrt(-1).*(erfi(-sqrt(-1).*E))))))) % equation (3)
Zf = uint64(((1-(sigma/2)).*Ff) + (sqrt(-1).*sqrt(pi/2).*((a.*c.*sigma)/4).*exp(-((2.*pi.*f+omega0).*(c.^2.*(2.*pi.*f+omega0)+2.*sqrt(-1).*b)))).*(-exp(4.*pi.*c.^2.*f.*omega0+2.*sqrt(-1).*b.*omega0).*((-sqrt(-1).*erfi(((tmax-b+sqrt(-1).*c.^2).*(2.*pi.*f-omega0))/(sqrt(2).*c)))-(-sqrt(-1).*erfi(((t0-b+sqrt(-1).*c.^2).*(2.*pi.*f-omega0))/(sqrt(2).*c))))+(-sqrt(-1).*(erfi(((tmax-b+sqrt(-1)*c.^2).*(2.*pi.*f+omega0))/(sqrt(-1).*c))))-(-sqrt(-1).*erfi(((t0-b+sqrt(-1).*c.^2).*(2.*pi.*f+omega0))/(sqrt(-1).*c))))) % equation (5)
figure(6)
plot(f,Zf) % plot of Magnitude of G (eq 5) vs frequency for f:(10^6 to 10^10)
% code
end
0 Comments
Answers (1)
Walter Roberson
on 11 Aug 2015
Edited: Walter Roberson
on 11 Aug 2015
>> uint64(1) + (-1+1i)
Error using +
Complex integer arithmetic is not supported.
>> uint64(1) + uint8(1)
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.
When you do an arithmetic operation on a uint64() the other operand must be a non-complex uint64() or must be a scalar non-complex double.
Complex uint64 are allowed: you just cannot do any arithmetic on them.
>> uint64(-1+1i)
ans =
0 + 1i
>> uint64(-1+1i) + 0
Error using +
Complex integer arithmetic is not supported.
>> uint64(-1+1i) + uint64(0)
Error using +
Complex integer arithmetic is not supported.
Work around: use real() and imag() to split the values, do the arithmetic on the parts separately, and complex() them back together.
But the real fix is to not use uint64 without good purpose.
2 Comments
Walter Roberson
on 11 Aug 2015
If you insist on using uint64 then use the work-around I indicated. You could even make an anonymous function out of it:
pluscomplex_uint64 = @(A,B) complex(real(A)+real(B),imag(A)+imag(B))
then replace the problem sums with calls to pluscomplex_uint64 and that will get you through. Until, of course, the place you try to multiply or divide or subtract the uint64 numbers...
But you should not be using uint64 for this purpose at all: just use isnan() to find out where the NaN's are and replace them.
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!