필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

searching for a better approach for solving a 3-D matrix

조회 수: 1 (최근 30일)
Udit Srivastava
Udit Srivastava 2016년 10월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
Hey guys,
I need to solve the following equation.
u(i,j,k+1)=(2*dt/3).*(u(i,j,k).*(u(i+1,j,k)-u(i-1,j,k))./(2*dr)+u(i,j,k-1).*(u(i,j+1,k-1)-u(i,j-1,k-1))./(2*dz));
where dt and dr are some known constants.
The approach I can think of is given below:
for i=2:n, for j=2:n, for k=2:n
u(i,j,k+1)=(2*dt/3).*(u(i,j,k).*(u(i+1,j,k)-u(i-1,j,k))./(2*dr)+u(i,j,k-1).*(u(i,j+1,k-1)-u(i,j-1,k-1))./(2*dz));
end, end, end
Is there any better approach to solve the same equation?
Please help me with this problem and suggest me a better approach, for my approach is not good enough for very long equations including 3 subscripted independent variables i, j, k where each denote r, z and time(t) components respectively, working in cylindrical coordinate system.
Thank you.
Udit Srivastava.

답변 (1개)

KSSV
KSSV 2016년 10월 13일
How about?
i = 2:n ;
j = 2:n ;
for k=1:n
u(i,j,k+1)=(2*dt/3).*(u(i,j,k).*(u(i+1,j,k)-u(i-1,j,k))./(2*dr)+u(i,j,k-1).*(u(i,j+1,k-1)-u(i,j-1,k-1))./(2*dz));
end
  댓글 수: 2
Udit Srivastava
Udit Srivastava 2016년 10월 13일
편집: Udit Srivastava 2016년 10월 13일
Sir, I actually want to remove the 'k' term from my equation and adjust it somewhere else so that the equation works like a 2-D matrix, making it look less cumbersome, like putting an outer loop on 'k' or something like that. Is it anyway possible?
KSSV
KSSV 2016년 10월 13일
It is possible...you have to save only two steps of k i.e u(i,j,1) and u(i,j,2). Every time you have to save the result into a file.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by