Why does the for loop give wrong answer

1 回表示 (過去 30 日間)
czakar
czakar 2019 年 11 月 17 日
編集済み: czakar 2019 年 11 月 17 日
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 件のコメント
Muhammad Usman
Muhammad Usman 2019 年 11 月 17 日
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 2019 年 11 月 17 日
i multiply *1000 since the pressures is taken in kPa

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 11 月 17 日
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 件のコメント
Guillaume
Guillaume 2019 年 11 月 17 日
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 2019 年 11 月 17 日
編集済み: czakar 2019 年 11 月 17 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by