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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by