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.
1 次查看(过去 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
0 个评论
回答(1 个)
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!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!