필터 지우기
필터 지우기

summing two 3d matrices to check convergence

조회 수: 2 (최근 30일)
Thales
Thales 2017년 9월 5일
편집: Matt J 2017년 9월 5일
Given two 3d matrices, obtained in a iterative process as the solution to a PDE, I want to check convergence. To do so, I check:
abs( sum( A(:) - Aold(:) ) ) < eps
Is this the best way to do it? I mean, if I declare
A = rand(100,200,50);
B = rand(100,200,50);
And if I check
check1 = abs( sum( A(:)-B(:) ) );
check2 = abs( sum(sum(sum( A-B ) ) ) );
check3 = abs( sum(A(:)) - sum(B(:)) );
check4 = abs( sum(sum(sum(A))) - sum(sum(sum(B))) );
They should give the same answer. However,
>> check1-check2
ans =
2.3306e-12
>> check1-check3
ans =
3.8846e-09
>> check1-check4
ans =
-2.4812e-10
>> check2-check3
ans =
3.8823e-09
>> check2-check4
ans =
-2.5045e-10
>> check3-check4
ans =
-4.1327e-09
So it clearly is not exactly the same thing. What is the difference between the methods and what is the difference between sum(A(:)) and sum(sum(sum(A))) ? If I want to check convergence on a iterative process, what is the best way to do it?
  댓글 수: 1
Matt J
Matt J 2017년 9월 5일
편집: Matt J 2017년 9월 5일
I think you really meant
sum(abs(A(:)-Aold(:)))<eps
This is the same as my Answer below, with p=1.

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

채택된 답변

Matt J
Matt J 2017년 9월 5일
편집: Matt J 2017년 9월 5일
norm(A(:)-Aold(:),p)<eps
where you choose p corresponding to your favorite p-norm

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by