필터 지우기
필터 지우기

Why the result does change when ı add other rows in Matrix?

조회 수: 1 (최근 30일)
Merve Ala
Merve Ala 2023년 1월 13일
댓글: Steven Lord 2023년 1월 13일
I am trying basic multiplication on Matlab. For the first row, it calculates in true way. But when ı add other rows, it calculates first row wrong.
l_1=600
A= 48.6
K = [12, 6*(l_1), -12 , 6*(l_1) ;
6*(l_1), 4*(l_1)^2 , -6*(l_1), 2*(l_1)^2 ;
-12, -6*(l_1), (12), -6*(l_1) ;
6*(l_1), 2*(l_1)^2, -6*(l_1), 4*(l_1)^2 ]
K_result=K.*A
and the result is
K_result =
1.0e+07 *
0.0001 0.0175 -0.0001 0.0175
0.0175 7.0000 -0.0175 3.5000
-0.0001 -0.0175 0.0001 -0.0175
0.0175 3.5000 -0.0175 7.0000
it doesnt calculate A*12 the result must be 583.3 but it shows 0.0001. When i just calculate first row it calculates in true.
K = [12, 6*(l_1), -(12), 6*(l_1)]
K_result=K.*A
K_result =
1.0e+05 *
0.0058 1.7500 -0.0058 1.7500

채택된 답변

Kevin Holly
Kevin Holly 2023년 1월 13일
It is giving the correct result. It is just rounded. I changed format to long below.
l_1=600;
A= 48.6;
K = [12, 6*(l_1), -12 , 6*(l_1) ;
6*(l_1), 4*(l_1)^2 , -6*(l_1), 2*(l_1)^2 ;
-12, -6*(l_1), (12), -6*(l_1) ;
6*(l_1), 2*(l_1)^2, -6*(l_1), 4*(l_1)^2 ];
K_result=K.*A
K_result = 4×4
1.0e+07 * 0.0001 0.0175 -0.0001 0.0175 0.0175 6.9984 -0.0175 3.4992 -0.0001 -0.0175 0.0001 -0.0175 0.0175 3.4992 -0.0175 6.9984
format long
K_result=K.*A
K_result = 4×4
1.0e+07 * 0.000058320000000 0.017496000000000 -0.000058320000000 0.017496000000000 0.017496000000000 6.998400000000000 -0.017496000000000 3.499200000000000 -0.000058320000000 -0.017496000000000 0.000058320000000 -0.017496000000000 0.017496000000000 3.499200000000000 -0.017496000000000 6.998400000000000
  댓글 수: 2
Merve Ala
Merve Ala 2023년 1월 13일
Oh thank you so much
Steven Lord
Steven Lord 2023년 1월 13일
In this case IMO format longg is even better.
l_1=600;
A= 48.6;
K = [12, 6*(l_1), -12 , 6*(l_1) ;
6*(l_1), 4*(l_1)^2 , -6*(l_1), 2*(l_1)^2 ;
-12, -6*(l_1), (12), -6*(l_1) ;
6*(l_1), 2*(l_1)^2, -6*(l_1), 4*(l_1)^2 ];
format longg
K_result=K.*A
K_result = 4×4
1.0e+00 * 583.2 174960 -583.2 174960 174960 69984000 -174960 34992000 -583.2 -174960 583.2 -174960 174960 34992000 -174960 69984000

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by