Floating Point Accuracy Problem or Human Error?
Mostra commenti meno recenti
I am trying to check my analytic solutions to a (somewhat ugly) system of equations by using sym/solve.
To preview, my problem is this: It seems that my analytic solutions match up with those returned by solve. The difference between the two solutions is on the order of 1e-16 at most. However, when I then multiply each solution by a vector one of the key coefficients is slightly greater than one in one case and less than one in the other. My (broader) conclusions hinge on this fact.
Here's some pseudo-code of what I'm doing:
syms x y real
z = sym('z',3);
% 'Solve' Solution
to_solve = a * z == b * z + c * (x - d * y) ....;
[zs1,zs2,zs3,zs4] = solve(to_solve,z);
zs = [zs1,zs2,zs3,zs4]';
vpa(zs,4);
ans =
0.05146*y + 7.078*x
0.1465*y + 0.3384*x
0.06446*y - 1.776*x
1.416*x - 0.04118*y
% Analytic Solution
zas = p * x + q * y;
vpa(zas,4);
ans =
0.05146*y + 7.078*x
0.1465*y + 0.3384*x
0.06446*y - 1.776*x
1.416*x - 0.04118*y
% Compare - Solutions are very close
disp(vpa(zas - zs,5));
% Test Outcome - Solve for x as ftn of y
to_solve2_s = x == r' * zs;
xs = solve(to_solve2_s,x);
to_solve2_as = x == r' * zas;
xas = solve(to_solve2_as,x);
And then I find that xas < 0 while xs > 0.
Might this just a matter of floating point accuracy? If so, which solution should be "trusted"? Any tips on making the solution less fragile?
1 Commento
William Wooley
il 8 Set 2016
Risposte (0)
Categorie
Scopri di più su Common Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!