generated "unvaforable zero" value from multiplying two matrices, how to solve/correct it?

12 次查看(过去 30 天)
for simplicity, i have a two matrices A and B generated by matlab like below. when i calculated manually by excel with the function mmult(A;B) the value of C is vaforable like this. even when i increasing the decimal. especially the value of cell matrix C at 3,1 it was definetly zero
but when i multiply them in matlab i got value of C like this
how to deal with this type of problem? any guidance will help me alot, because i got bunch of wild value zero like this :( thanks a lott.
the following attachments is my full code, matrix A is k_sup and matrix B is uaa, and matrix C is Fsupt in my line code. input3Dxlsx is my input.
P.S
i tried calculate separately with new script (like the following A*B bottom), copy those matrices from generated excel (so the value is accurate), and the generated value of matrix C is entirely different, like this:
here is the following matrix A and B i copy from generated excel
A = [-3710000000 0 0 0 0 0;
0 -12624305.56 0 0 0 75745833.33;
0 0 -2318750 0 -13912500 0;
0 0 0 -69358333.33 0 0;
0 0 13912500 0 55650000 0;
0 -75745833.33 0 0 0 302983333.3]
A = 6×6
1.0e+09 * -3.7100 0 0 0 0 0 0 -0.0126 0 0 0 0.0757 0 0 -0.0023 0 -0.0139 0 0 0 0 -0.0694 0 0 0 0 0.0139 0 0.0556 0 0 -0.0757 0 0 0 0.3030
B = [0
0
-0.025876011
0
0.004312668
0]
B = 6×1
0 0 -0.0259 0 0.0043 0
C = A*B
C = 6×1
1.0e+05 * 0 0 0.0000 0 -1.2000 0
  1 个评论
Stephen23
Stephen23 2025-1-23
编辑:Stephen23 2025-1-23
"P.S i tried calculate separately with new script (like the following A*B bottom), copy those matrices from generated excel (so the value is accurate), and the generated value of matrix C is entirely different"
MATLAB returns the same result (although perhaps displayed to a different precision):
A = [-3710000000,0,0,0,0,0;; 0,-12624305.56,0,0,0,75745833.33;; 0,0,-2318750,0,-13912500,0;; 0,0,0,-69358333.33,0,0;; 0,0,13912500,0,55650000,0;; 0,-75745833.33,0,0,0,302983333.3]
A = 6×6
1.0e+09 * -3.7100 0 0 0 0 0 0 -0.0126 0 0 0 0.0757 0 0 -0.0023 0 -0.0139 0 0 0 0 -0.0694 0 0 0 0 0.0139 0 0.0556 0 0 -0.0757 0 0 0 0.3030
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = [0; 0; -0.025876011; 0; 0.004312668; 0]
B = 6×1
0 0 -0.0259 0 0.0043 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
format long G
C = A*B
C = 6×1
1.0e+00 * 0 0 0.00695624999207212 0 -120000.0288375 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

请先登录,再进行评论。

回答(1 个)

Abhiram
Abhiram 2025-1-23
编辑:Abhiram 2025-1-23
Hello Adli,
I understand you are trying to multiply two matrices and in places of zero you are getting some nominal values.
To resolve the issue, we can set the values less than a chosen tolerance to zero explicitly by defining a “tolerance ” variable to an appropriate value. For the given sample matrix “C”, the desired result can be achieved with the code given below:
% Define the tolerance
tolerance = 1e-2;
% Round small values in C to zero
C(abs(C) < tolerance) = 0;
% Display the result with long format
format long
disp(C);
In addition, the “format” functionality in MATLAB can be used to change the output display format to display the required number of decimal values for a numeric value. An example usage of the MATLAB “format” function is given in the code below:
A = 0.100000043434;
format short
disp(A);
format long
disp(A);
Refer to the documentation for the MATLAB “format” function for more details:

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by