필터 지우기
필터 지우기

Order of Addition changes answer? Approx 0 or actually 0

조회 수: 1 (최근 30일)
aldburg
aldburg 2017년 11월 25일
댓글: aldburg 2017년 11월 26일
I've been trying to figure out for half a day why my Solution was not 0 by an order of 1.0e-14 or e-15. When I added several matrices together I noticed that the order to which I add them changes the value. Sol_1=0 (3X3) Matrix but Sol_2=~0(3X3). Please help, I can't figure it out.
clear
E1=80.32
E2=5.590
v12=0.338
G12=3.590
Composite_Properties=[E1 E2 v12 G12 0 0.254;
E1 E2 v12 G12 -45 0.254;
E1 E2 v12 G12 45 0.254;
E1 E2 v12 G12 45 0.254;
E1 E2 v12 G12 -45 0.254;
E1 E2 v12 G12 0 0.254]
[r,c]=size(Composite_Properties)
A=cell(1,r)
for i = 1:r
A{i}=Q_BAR(Composite_Properties(i,1),Composite_Properties(i,2),Composite_Properties(i,3),Composite_Properties(i,4),Composite_Properties(i,5))*Composite_Properties(i,6)
end
A_SUM=A{1};
for i=2:(c)
A_SUM=A_SUM+A{i};
end
A_SUM
z_k_bar=zeros(1,r,'double')
for j=1:r
z_k_bar(j)=(((-r/2)+((2*j-1)/2))*Composite_Properties(j,6))
end
clear i j
%Making B Matices
B=cell(1,r)
for i = 1:r
B{i}=Q_BAR(Composite_Properties(i,1),Composite_Properties(i,2),Composite_Properties(i,3),Composite_Properties(i,4),Composite_Properties(i,5))*z_k_bar(1,i)*Composite_Properties(i,6)
end
%Summation of B Matrices
B_SUM=B{1}
for j=2:c
B_SUM=B_SUM + B{j};
end
B_SUM
Sol_1=B{1}+B{6}+B{2}+B{5}+B{3}+B{4} %0 Matrix%
Sol_2=B{1}+B{2}+B{3}+B{4}+B{5}+B{6} %not Zero why???%
  댓글 수: 5
aldburg
aldburg 2017년 11월 25일
Any way I can improve accuracy or do I have to implement an if statement so if its less than some number (epsilon) then the elements of the matrix is 0?
John D'Errico
John D'Errico 2017년 11월 25일
You can essentially never improve the accuracy so much that floating point computations will be perfect when using floating point arithmetic. Use of higher precision simply pushes the errors down to smaller levels. Yes, you can use my HPF toolbox to do high precision computations, and with some effort, you can do better, at a cost of time.
Instead, you really need to understand how precision impacts your computations, learn what are acceptable errors in computations, and learn how to minimize any errors by the use of robust computational schemes.

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 26일
You can make some small changes for higher accuracy if you have the Symbolic Toolbox. Modified version enclosed.
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 11월 26일
There was also the change to how z_k_bar was initialized; you were always initializing it as double, and I change that to initialize to the same as whatever the table is (so if you commented out the sym of the table then the z_k_bar would quietly go back to using double.)
aldburg
aldburg 2017년 11월 26일
I didn't notice that, thank you for pointing that out. You have helped me a lot the past few weeks. Started out not knowing what a double or a string was and now I am here :)

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

추가 답변 (0개)

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by