Numerical round off / instability help? How to get more precision?
Show older comments
I am trying to calculate the complex magnetic attenuation coefficient using the code below (for 3 different materials: Al, Cu & Steel):
clear all
close all
num_pt = 10000; % number of data points
fmax = 30000; % max frequency in Hz
f = (1:fmax/num_pt:fmax); % frequencies Hz
w = 2*pi.*f; % angular frequency
u = 4*pi*10^(-7); % permeiability of the metal
s = 1/(6.01349*10^(-8)); % Al condictivity of the metal
% s = 1/(2.37230*10^(-8)); % Cu condictivity of the metal
% s = 1/(1.55363*10^(-7)); % Steel condictivity of the metal
d0 = sqrt(2./(w.*u*s)); % skin depth
k0 = 1./d0;
R1 = 0.0181; % inner radius of pipe
R2 = 0.0193; % outer radius of pipe
v1 = k0.*R1*(1i+1);
v2 = k0.*R2*(1i+1);
% bessel functions of first and second kind for calculation of a the
% complex attenuation coefficient.
J0_v1 = besselj(0,v1);
J0_v2 = besselj(0,v2);
J1_v1 = besselj(1,v1);
J1_v2 = besselj(1,v2);
Y0_v1 = bessely(0,v1);
Y0_v2 = bessely(0,v2);
Y1_v1 = bessely(1,v1);
Y1_v2 = bessely(1,v2);
% break complex attenuation into parts for calculation
A = (J0_v1.*Y1_v1 - J1_v1.*Y0_v1);
B = (J0_v2.*Y1_v1 - J1_v1.*Y0_v2);
C = (k0.*R1./2);
D = (J0_v2.*Y0_v1 - J0_v1.*Y0_v2);
% complex attenuation coefficient
a = A./(B+C.*D.*(1+1i));
atacc = (a.*conj(a));
% high frequency approximation to a
% p = 2*sqrt(R2/R1).*exp(-k0.*(R2-R1))./sqrt(1+k0.*R1+k0.^2.*R1^2/2);
plot(f,atacc);
axis([0,fmax,0,1])
My issue is that I am getting numerical instability for high frequency. Running the above code you will see erratic spikes (starting around 15kHz) which should not be there. It is clear this is a precision issue as one can convert all values to 'single' and the erratic behaviour moves to lower frequencies. Is there anything that I can do to increase the precision to allow calculation at higher frequencies without error.
Thank you very much for your time and comments. BN
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!