Yaw error calculation for a wind turbine using matlab - matlab

We know theoretically that
yaw error = wind direction - nacelle direction
After I have wind direction and nacelle direction data sets and hence calculated yaw error using above formula. I have calculated the absolute value of yaw error. Once I calculated the yaw error values I found that this calculation is not correct and hence I have to modify further with this formula
Error = 360 - yaw error
So basically I have to run a for look which is going to check my each yaw error value and if there is some wrong with that data it must replace with original data.. for example if my yaw error values are 10,20,30,40,300. it seems there is a wrong with 300 value because of quadrant changes hence it would replace with
error = 360 - 300 = 60. I have written a code for this below :
for i = 1:yaw error
if yaw_error > 180
error = 360 -yaw_error
else
end
end
yaw error = [yaw error error];
Can you help me where I am wrong ??
Thanks in advance :)

The one-liner of Umar is correct and elegant.
For your understanding, I have debuged your original code to:
yaw_error = [ 10,20,30,40,300]
for i = 1:numel(yaw_error)
if yaw_error(i) > 180
yaw_error(i) = 360 -yaw_error(i);
end
end;
yaw_error

From what I understand from your question
lets say x is a matrix of yaw error values
x = [10 20 30 40 190 160 70 120 300 180 30]
you find the indices of the values greater than 180
z = find(x > 180)
z =
5 9
subtract them from 360
>> d =360 - x(z)
d =
170 60
and place them back in the orignal matrix
>> x(z) = d
x =
x =
10 20 30 40 170 160 70 120 60 180 30
One-liner would be
x(find(x > 180)) = 360 - x(find(x > 180)) or x(x>180)=360-x(x>180)

Related

4x4 matrix rotation unexpected: 200°+45°=115°

I would like to make a rotation using 4x4 matrix in Swift, but it has unexpected behavior: 200 degrees + 45 degrees = 115 degrees, and not 245
let degree200 = Angle(degrees: 200).radians
let degree45 = Angle(degrees: 45).radians
// 200 degrees + 45 degrees
let rotationMatrix = float4x4(simd_quatf(angle: Float(degree200+degree45), axis: SIMD3<Float>(0, 1, 0)))
// it prints 115 degree, and not 245
print(Angle(radians: Double(simd_quatf(rotationMatrix).angle)).degrees)
I assume that's a typo, and you in fact meant -115 degrees? (remainder(245, 360)) When using quaternions & Matrices to express orientations, you can only expect to see values of -180 to +180 degrees when converting those values back to Euler angles.
In general it is impossible to convert back to Euler angles from either a quaternion or matrix and get the original input values back. You either store the original Euler angles and present those to the user, or you will have to have a known starting Euler value and apply an Euler filter to obtain approximately correct results.
The only correct way to get your expected result is to NOT print the value after conversion to quats:
print((degree200 + degree45). degrees)
Well I know 115 and 245 are 360. Just a guess but maybe you're rotating the wrong way?? Maybe try negative values and see what happens.

Angles in Matlab

i need to calculate some expression for all angles from 0 to 90 degrees increments 10 degrees (of cause expression depends on some trigonometrical function).
It looks like:
for alpha = 0:10:90
func(alpha) = c * sin(alpha)
end
Who know how to work with degrees, tell, please
It should be:
for 0:pi/18:pi/2

Plotting speed and distance calculated using accelerometer

I am working on basic distance calculation using accelerometer by dragging object on a single axis for physics class in MATLAB and have problem with plotting data.
My steps are:
1) After calibrating device to read zero g on every axis, I eliminate drift errors:
X_real = X_sample - X_calibrated;
if(X_real <= X_drift )
{
X_real = 0;
}
Where X_drift is 2 mg (From datasheet of accelerometer)
2) Calculate velocity:
velocity = 0; % On start
% Integration
v(i) = v(i-1) - x(i-1)-(x(i)+x(i-1)+x(i-2)+x(i-3))/4;
%Check if we stopped
if(x(i-1)==0 && x(i)==0)
v(i)=0;
end
%Check if velocity is under 0 (Not allowed)
if(v(i) < 0)
v(i)=0;
end
velocity = velocity + v(i);
3) Calculate distance:
distance = 0; % On start
%Integration
s(i) = s(i-1) + v(i-1) + (v(i)-v(i-1)-v(i-2)-v(i-3))/4;
distance = distance + s(i);
After testing this by dragging accelerometer on table 20 cm i got these results:
velocity = 0.09 m/s
distance = 0.21 m
time = 3.2s
Error of 1 cm is OK for classroom.
Chart tells something different:
I tried to plot distance after this:
s(i) = s(i)+s(i-1);
And got 21 cm on chart but after 6 s not after 4 s where it should be.
What am I doing wrong?
*UPDATE: Position y value is in mm not cm! Sorry
Im sorry for asking for help, i thought my formulas were ok, but they didn't. After step by step calculations my final solution is:
1) Velocity:
v(i) = v(i-1) - x(i-1)-(x(i)+x(i-1))/2;
2) Distance:
s(i) = s(i-1) + v(i-1)+(v(i)+v(i-1))/2;
And chart is:
Sorry once more time. I hope this will help someone calculating velocity and distance. It surely helped me as lesson to better study my code next time before asking for help.

Matlab Stepinfo Function

S = stepinfo(Y,T,180,'SettlingTimeThreshold',ST) ;
ts=S.SettlingTime;
in this does it mean ts is the time at which |Y-180| becomes less than ( ST/100 )or something else...
in my code though |Y-180| is less than ST/100 but i am getting ts = NAN;
pls help me out
My code:
if ee(end)>160
S = stepinfo(ee,times,180,'SettlingTimeThreshold',0.01);
else
S = stepinfo(ee,times,0.5,'SettlingTimeThreshold',1);
end
settling_time = S.SettlingTime;
end
where 'ee' is an array of values at each 'times'
ee is basically error angle which becomes 180 or 0 after some time..
thanks
From the help:
The response has settled when the error |y(t) - yfinal| becomes
smaller than a fraction ST of its peak value.
This means that it's the fraction of the peak error value, not an absolute threshold - e.g. if your system was something that started at around 30, and eventually rose and settled at near 180 (yfinal = 180), then the max error is 150, and the threshold would be 0.01*150 = 1.5. So it would need to get to 178.5 (180-1.5).
If your system started at 100 and settled at about 180, your max error is 80, and the threshold is then only 0.8, so your value needs to be at 179.2.
Look at what your min(ee) and max(ee) are and then decide on what a sensible threshold is.
EDIT:
If you want to set a fixed threshold you'll have to calculate it on the fly:
desiredthreshold = 1.8 % absolute value, e.g. 0.01*180
maxerror = 180-min(ee); % assuming your values are all between 0 and 180
actualthreshold = 1.8/maxerror; %if your min value is 0 then this goes to 0.01, otherwise it will be larger

How does Maple 14 convert Fahrenheit to Celcius

using
convert(32, temperature, Fahrenheit, Celsius)
I get 0, the known freezing point of water in Celsius
using
convert(32, units, Fahrenheit, Celsius)
I get 160/9 approx. 17.778 Celcius
How does Maple get this answer 160/9
I tried this as well...
using
convert(100, temperature, Celsius, Fahrenheit)
I get 212
using
convert(100, units, Celsius, Fahrenheit)
I get 180
This is a "relative" versus "absolute" issue.
In absolute terms, 1 deg C is 33.8 deg F. That's on an absolute scale.
In other words, 1 deg C above the freezing point of water is the same temperature as 1.8 deg F above the freezing point of water. It's an absolute scale; eg. the fixed freezing point where they match at 0 deg C = 32 deg F.
And that leads to the well known relative scale, 1 deg C = 9/5 def F. That means that for every 1 deg C of increase, there is a 9/5 deg F increase. This is a relative scale; there's no fixed reference such as freezing or boiling points.
convert/temperature does the absolute scale temperature conversion.
convert/units does the relative scale "temperature increment" conversion.
Suppose I say to you, what's 10 deg C in Fahrenheit? In your head you might do it like so: Divide by 5 to get 2, multiply by 9 to get 18, and add 32 to get a final result of 50 deg F. You added the 32 deg F at the end, because this was an (absolute scale) temperature question. Now what if I subsequently asked a second question: what's 11 deg C in Fahrenheit? That's 1 deg C more than before. How many deg F do you need to add to the previous answer? It's certainly not 33.8 deg F more that you'd add to the earlier answer. No, you'll just take 1 deg C = 1.8 deg F, since this is an increment. And you'll get 50 deg F + 1.8 deg F = 51.8 deg F. That was a relative increment over the first answer.