Percentage difference for two matrices
function [p]=calcPoly(m,K)
%n = order, K=m'th zero of the n'th order bessel function
r = 0:.1:1;
R = 1;
stage1 = 0;
stage2 = 0;
ans = 0;
bessel = besselj(m,K*r/R);
[p,s] = polyfit(r,bessel,6);
z = polyval(p,r);
figure;plot(bessel,'*');
hold on;plot(z,'g');
besselsum = sum(bessel)
zsum = sum(z)
stage1 = besselsum - zsum
stage2 = stage1 / zsum
ans = stage2 * 100
I'm trying to find out a percentage difference for bessel and z (the polynomial approximation), however, the difference is very small. How will I calculate a percentage difference for these small values? I just want to prove how accurate the Polynomial approximation is, I thought it would be nice to have some solid data as well as a graph.
Thanks in advance
%n = order, K=m'th zero of the n'th order bessel function
r = 0:.1:1;
R = 1;
stage1 = 0;
stage2 = 0;
ans = 0;
bessel = besselj(m,K*r/R);
[p,s] = polyfit(r,bessel,6);
z = polyval(p,r);
figure;plot(bessel,'*');
hold on;plot(z,'g');
besselsum = sum(bessel)
zsum = sum(z)
stage1 = besselsum - zsum
stage2 = stage1 / zsum
ans = stage2 * 100
I'm trying to find out a percentage difference for bessel and z (the polynomial approximation), however, the difference is very small. How will I calculate a percentage difference for these small values? I just want to prove how accurate the Polynomial approximation is, I thought it would be nice to have some solid data as well as a graph.
Thanks in advance
0
Comments
sum((bessel - z).^2)/length(bessel);
if you want pct error, i'd suggest absolute error:
sum(abs(bessel - z)./abs(bessel))*100;
Thank you, I just worked out a Percentage error as
x = abs((bessel-z)./z);
q = sum(x) / 11;
Is this correct?
Would there be a point in using all of the error checking or just one?