Different results by changing the order of operations
이전 댓글 표시
Hi all,
Replicating the cardiac nodal cell model (set of ODEs) from MATLAB (2018a, 64bit) to Simulink I found different results in solution of a particulal equation (without derivatives). Later, I also found the same difference in Matlab results either by changing the order of mathematical operations (e.g. (x./y).*z ~= x.*z./y), or calculating parts of the equation separately first, and then combining them. Example of the latter case is below (see also attached file). The problem appears in equation in the line 451. Temporal variables al57 and al571 show different results, though the difference is not too big. For the first time step, 1.1324 and 1.0209, respectively, and the second value seems correct being checked with calculator, with the same (2nd) result in Simulink.
A(:,57) = 1.0+ (S(:,6)./C(:,19)).*(1.0+exp(( - C(:,16).*S(:,1))./C(:,49))+C(:,14)./C(:,23))+ C(:,14)./C(:,20)+power(C(:,14), 2.0)./ (C(:,20).*C(:,21))+power(C(:,14), 3.0)./( C(:,20).*C(:,21).*C(:,22));
al57 = A(:,57)
al570 = (1.0+exp(( - C(:,16).*S(:,1))./C(:,49))+C(:,14)./C(:,23))+C(:,14)./C(:,20)+power(C(:,14), 2.0)./ (C(:,20).*C(:,21))+ power(C(:,14), 3.0)./( C(:,20).*C(:,21).*C(:,22));
al571 = 1.0+ (S(:,6)./C(:,19)).*al570
-----
al57 =
1.1324
al571 =
1.0209
Can anyone comment or give some advice? Thanks in advance.
댓글 수: 2
"..difference in Matlab results either by changing the order of mathematical operations"
As operations on binary floating point numbers are neither associative nor commutative, why do you particularly expect the outputs to be exactly the same? Floating point mathematics is definitely not the same as symbolic or algebraic mathematics.
Search this forum for "floating point" for hundreds of threads disscussing this topic.
Most likely your algorithm is numerically unstable, e.g. incudes differences of very similar numbers. If you explained the algorithm them someone might be able to help you with that.
Maxim
2020년 1월 6일
채택된 답변
추가 답변 (1개)
Etsuo Maeda
2020년 1월 6일
0 개 추천
"Validated numerics" will help you to understand your problem.
My best guess is that "vpa" in Symbolic Math Toolbox will show you a proper result.
HTH
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!