Fixing MATLAB Loop Error in TSR Calculation for VAWT

In summary: Did you mean to use j or i in your expression for TSR?In summary, the person is attempting to write a MATLAB code to calculate the Tip Speed Ratio of a vertical axis wind turbine at different blade path angles and corresponding speeds. However, they are getting an error message due to attempting to access an array with a non-integer index. They are seeking suggestions to correct their calculations.
  • #1
Thusithatck
13
0
I'm trying to write a MATLAB code but I get an error message which I'm not sure why. The code is follows as,

%%%%% Code %%%%%

for i = 1:1:v;
for j = 1:0.1:a

TSR(i,j)=wR/i;

end
end

%%%%% Code %%%%%

Here 'a' is taken as 90 degrees, which represents blade path of a vertical axis wind turbine and 'v' is taken as the velocity (m/s) of air and wR (omega) is taken as 5 which is the angular speed of the wind turbine. What I'm trying to estimate is the the Tip Speed Ratio of a vertical axis wind turbine at different blade path angle which corresponds to different speeds. The equation is given below which calculates the Tip Speed Ratio.

TSR = (wR/v) = [wind turbine angular speed / speed of wind]

The error message that I'm getting is given below.

? Attempted to access TSR(1.1,1); index must be a positive integer or logical.

Error in ==> Experiment at 57
TSR(i,j)=wR/i;


Could some one give any suggestions to correct my calculations.
 
Physics news on Phys.org
  • #2
Thusithatck said:
I'm trying to write a MATLAB code but I get an error message which I'm not sure why. The code is follows as,

%%%%% Code %%%%%

for i = 1:1:v;
for j = 1:0.1:a

TSR(i,j)=wR/i;

end
end

%%%%% Code %%%%%

Here 'a' is taken as 90 degrees, which represents blade path of a vertical axis wind turbine and 'v' is taken as the velocity (m/s) of air and wR (omega) is taken as 5 which is the angular speed of the wind turbine. What I'm trying to estimate is the the Tip Speed Ratio of a vertical axis wind turbine at different blade path angle which corresponds to different speeds. The equation is given below which calculates the Tip Speed Ratio.

TSR = (wR/v) = [wind turbine angular speed / speed of wind]

The error message that I'm getting is given below.

? Attempted to access TSR(1.1,1); index must be a positive integer or logical.

Error in ==> Experiment at 57
TSR(i,j)=wR/i;


Could some one give any suggestions to correct my calculations.

I believe it's because you're attempting an index an array with a non-integer; by incrementing j in steps of 0.1, you're trying call out a 1.1'th element in TSR (i.e. the elements must be numbered 1, 2, 3, ...)
 
  • #3
Is TSR a previously defined matrix? If you're trying to store elements, as it's already been stated you must use a positive integer.

It doesn't look like you are using j in your program.
 

1. How can I fix a MATLAB loop error in TSR calculation for VAWT?

One possible solution is to check for any syntax errors in the code and make sure all variables are properly defined. Another solution is to try using a different loop structure, such as a while or for-each loop.

2. Why am I getting a loop error when calculating TSR for a VAWT in MATLAB?

This could be due to a variety of reasons, such as incorrect syntax, an undefined variable, or a logical error in the code. It is important to carefully check the code and debug any potential issues.

3. Is there a specific way to structure the loop for calculating TSR in MATLAB for a VAWT?

There is no one specific way to structure the loop, as it will depend on the specific problem and the desired output. However, it is important to ensure that the loop is properly defined and that all necessary variables and conditions are included.

4. How can I optimize my MATLAB loop for faster TSR calculation in VAWT analysis?

One way to optimize the loop is to use vectorization, which allows for performing operations on entire arrays of data at once rather than one element at a time. This can significantly improve the speed of the calculation.

5. Can I use a pre-existing MATLAB function to calculate TSR for a VAWT?

Yes, there are several pre-built functions in MATLAB that can be used to calculate TSR for a VAWT, such as "trapz" or "integral". These functions can help simplify the code and may also have built-in optimizations for faster calculation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top