필터 지우기
필터 지우기

error with calculating drag and lift forces in a square prism. The error i get is Index must not exceed 1. any help would be greatly appreciated.

조회 수: 4 (최근 30일)
Hello MATLAB Forums
I'm trying to calculate and plot the drag force and lift force over a period of time of a square prism using the navier stokes equation. I keep on getting an error in my code in line 253 saying that "Index in position 2 exceeds array bounds, index must not exceed 1". The Force part of the code is from lines 195 to 257. The rest of the code before lines 195 works fine. Any help would be greatly appreciated.
cheers
Daniel

답변 (1개)

Saurav
Saurav 2024년 4월 24일
Hello Daniel,
From the provided information, I understand that you are getting error in your code while trying to plot the drag and lift force of a square prism using the Navier-stokes equation.
As I can see, in the ‘force calculation’ part of your code, the initialization of the variables ‘F_fric’, ‘tau’, ‘F_L’ and ‘F_d’ is not done properly before using them in the equation inside the loop.
Here is how you can modify your code to resolve the error:
% Force calculation
for i=1:nx
for j=1:ny
F_fric(1:nx,1:ny) = 0; % Proper initialization of F_fric
tau(1:nx,1:ny) = 0; % Proper initialization of tau
F_L(1:nx,1:ny) = 0; % Proper initialization of F_L
F_d(1:nx,1:ny) = 0; % Proper initialization of F_d
if (i==1)
tau(i,j)=0;
F_fric(i,j)=0;
F_L(i,j)=0;
I hope this helps!
  댓글 수: 1
Daniel Pitigala
Daniel Pitigala 2024년 4월 24일
Hi Saurav
Thankyou for the response. I have put the changes in my code and it runs with no errors but my code seems to be running very slowly.

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

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by