Floating Point Accuracy Problem or Human Error?

1 次查看(过去 30 天)
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?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by