1
votes

I was given 2 equations in order to find the current. I tried to find the relative error, but i got a curve which doesn't make any sense to me -at least-.

a = 0:.0001:pi;
a0 = .2744;
ws = .5;
I2 = (-sin(pi/ws)/(cosh(pi*a0/ws)+cos(pi/ws)));
Ucpw = (((a0*sin(pi/ws)-sinh(pi*a0/ws))/(cosh(a0*pi/ws)+cos(pi/ws))));
exp2 = exp(-a0/ws*a);
I1 =(-sin(1/ws*pi))/(cosh(a0/ws*pi)+cos(1/ws*pi));
phi2 = atan(-I2/(1-Ucpw - a0*I2));
i1 = exp2.*(I1.*cos(1/ws.*a)+(1-Ucpw-a0*I1).*sin(1/ws.*a));
i2 = (-I2./sin(phi2)).*exp2.*sin(a/ws - phi2);
e = abs((i1-i2)./i1);
plot(a,e)

Var a stands for the angle which should be displayed in radians, Does this curve mean that the solutions have error only at pi/2 with the amplitude of 5.05e-12?

1
It is normal to have certain points with a higher error, for a simplified example take this code: a = 0:.0001:pi; plot(acos(cos(a))-a); - Daniel
I got some fun now; i set a to 2pi which corresponds to 360 electrical degrees and i got some more interesting stuff. But anyway i expected the error to have a more random distribution. Kind of frustrated tho. - sayid jetzenden
Floating point precision is no random effect, it is very deterministic and depends on the range of values. Check eps function. - Daniel
I was referring to the distribution of error, not to the magnitude nor to the error which comes from numerical limit representation. I mean, in this particular case, both the functions have the same outcome for the same inputs, except for some strict regions of pi/2,pi,3pi/2. I expected to have an error also near those values. - sayid jetzenden

1 Answers

0
votes

Using relative error in this example was not a good idea, because i1 turns into zero at pi/2. This is the reason for the spike in the relative error, which drowns out the rest of the graph. I suggest plotting the logarithm of the absolute error instead: plot(a,log(abs(i1-i2)))

error

As you can see, the error is not confined to pi/2 value. The magnitude exp(-36) is approximately the value of eps on my machine; both are about 2e-16. As Daniel said in a comment, it comes from the limitation of floating point precision.