Borrar filtros
Borrar filtros

Why does my subtraction yield different results?

2 visualizaciones (últimos 30 días)
Hylke Dijkstra
Hylke Dijkstra el 28 de Ag. de 2023
Respondida: William Rose el 28 de Ag. de 2023
I have been working on an analysis and after simplifying my code for speed the results came out differently even though I think I should have obtained the same results.
L = eye(n * c) / (eye(n * c) - A);
x_test = L * F * ones(p , 1);
isequal(eps(x),eps(x_test))
% so x and x_test are equal
x_1 = L * F * ones(p , 1) - (eye(n * c) - A_tilde) \ F_tilde * ones(p , 1);
x_2 = x - (eye(n * c) - A_tilde) \ F_tilde * ones(p , 1);
isequal(eps(x_1),eps(x_2))
The first isequal return me a one while the second isequal returns me a zero.
This means that x_test is equal to x but if I subtract the same vector on the RHS of the minus sign, I get a different result. I am not sure how this is possible. Could anyone point me in the right direction?

Respuesta aceptada

Matt J
Matt J el 28 de Ag. de 2023
Editada: Matt J el 28 de Ag. de 2023
isequal(eps(x),eps(x_test))=1 does not establish that x=x_test. You misunderstand what eps() does.
eps(1)
ans = 2.2204e-16
eps(1.1)
ans = 2.2204e-16
isequal(eps(1), eps(1.1))
ans = logical
1

Más respuestas (1)

William Rose
William Rose el 28 de Ag. de 2023
Can you provide more of your code? Why do you use the eps() function when testing the equality of two numbers or vectors or matrices? The following example shows that two unequal numbers can have equal eps's.
x1=1; x2=x1+1e-8; isequal(x1,x2), isequal(eps(x1),eps(x2))
ans = logical
0
ans = logical
1

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by