I'm using the trapz function on two sets of data and there's something wrong.
So you can understand my problem; y-axis is pressure coefficient Cp, x-axis is angle (49 values in total, 0:7.5:360), data with the green square matrix is the data obtained from the experiment, the red curve is basically Cpsin(angle) while the pink one is Cpcos(angle)
Using trapz on the red one works perfectly, it gives 7.5, and if I reverse the input arguments for trapz I get the negative of this number! The problem is with the pink graph, using trapz gives a huge number (it's wrong, I shouldn't be getting this) and when switching the input arguments I get another huge number, not the negative of the first number, that is weird, I don't know what is wrong, so I used quad (needs a function) to test the results of trapz
for i = 1:48
y = @(x) (Cp(i+1) - Cp(i)) / ( theta_rad(i+1) - theta_rad(i) ) * x .* sin(x);
clll(i) = -0.5* quad(y,theta_rad(i), theta_rad(i+1));
end
clll = sum(clll);
for j = 1:48
f = @(t) (Cp(j+1) - Cp(j)) / ( theta_rad(j+1) - theta_rad(j) ) * t .* cos(t);
cdddp(i) = 0.5* quad(f,theta_rad(j), theta_rad(j+1));
end
cdddp = sum(cdddp);
For the first loop (quad of the red curve) I got a very close answer, the error was probably due to the linear interpolation I used between points and for the second loop I got a sensible answer, a very small number which is in the range of the answer I'm looking for. I also tried trapezoidal rule in Excel and I got this huge number again, so it's something I'm doing wrong.
Edit:
I just found a mistake, I was using the trapezoidal using angles in degrees rather than radians! Now I'm getting much smaller numbers but I think there's another mistake because the integral using quad gives a more sensible answer.
Here's the code I'm using for trapz
Cdp = 0.5*trapz( theta*pi/180, Cp.*cosd(theta) ); %pressure drag coefficient
Cl = -0.5*trapz(theta*pi/180, Cp.*sind(theta) ); %lift coefficient
