Why does the for loop give wrong answer

1 vue (au cours des 30 derniers jours)
czakar
czakar le 17 Nov 2019
Modifié(e) : czakar le 17 Nov 2019
Hello, I am trying to do a few operations with data in order to make some graphs for my report. During our lab we took some readings and now need to calculate the pressure coefficient for higher and lower surface with different angles of attack. Where did i make an error, since the matlab does not calculate it properly. This is formula I used. C_p = (local_pressure - ambient_pressure)/0.5*rho*V^2
In matlab I used this for command
the answer for 1st pressure should be about about -2.5 yet matlab gives the answer -3.0646e+05
Could someone tell mem where I made the mistake?
I attached my workspace above.
for i = 1:10
C_p_l_10(i) = (1000*lower_pressure(1,i)-ambient_pressure(1))/0.5*ambient_air_density*velocity(1)^2
end
  2 commentaires
Muhammad Usman
Muhammad Usman le 17 Nov 2019
As you mentioned in your formula, there is no multiplication with 1000, but if you want to scale down your result then you multiply 1E-05 and your code look like:
for i = 1:10
C_p_l_10(i) = 1e-05*(lower_pressure(1,i)-ambient_pressure(1))/0.5*ambient_air_density*velocity(1)^2;
end
C_p_l_10
simply display tour values outside loop
czakar
czakar le 17 Nov 2019
i multiply *1000 since the pressures is taken in kPa

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 17 Nov 2019
For a start make sure that your numbers are all in the correct units. It looks like your density is in SI () but your pressure certainly isn't and it doesn't even look like local pressure and ambient pressure are in the same unit. If you're using SI, they both should be in Pascal.
Secondly, matlab follows the rules of mathematics. is calculated as not , so the formula that you're using is: instead of the correct
Note that you don't need a loop to apply your formula:
C_p_l_10 = (lower_pressure(1, :) - ambient_pressure(1)) / (2 * ambient_air_density * velocity(1)^2);
The above assumes that everything is in compatible units.
And if the 3 different columns of ambient_pressure and velocity correspond to the 3 different rows (!) of lower_pressure then everything can be calculated at once:
%using (:) to transform row vectors into column vector to BE CONSISTENT with the shape of lower_pressure
%since we're operating with matrices and vectors now, using ./ and .^ to get memberwise operations
Cp = (lower_pressure - ambient_pressure(:)) ./ (2 * ambient_air_density * velocity(:).^2);
  3 commentaires
Guillaume
Guillaume le 17 Nov 2019
Ambient pressure is only 253 pascal? You're doing your experiment at near vacuum?
For that matter, why the lower pressure negative? I assume you're measuring relative pressure, but it can't be relative to ambient since ambient is non-zero.
Anyway, as I said, the main mistake is the lack of brackets around the denominator.
czakar
czakar le 17 Nov 2019
Modifié(e) : czakar le 17 Nov 2019
I corrected the brackets and it is fine now. it is not ambient pressure. The experiment was w aerofoil in wind tunnel with 10 pipes attached on top and bottom. I know what values to use where, not gonna lie could have made a mistake with naming them.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by