How can I restrict a parameter (turbulence intensity) to only positive values?

5 ビュー (過去 30 日間)
Rahul
Rahul 2023 年 5 月 8 日
コメント済み: E. Cheynet 2024 年 2 月 26 日
Hello,
I have a code in which the parameter u3 which denotes the turbulence intensity oscillates from positive to negative for each iteration. Since negative turbulence does not have any physical meaning, I hence want to restrict the same to only positive values. I'm finding it difficult to restrict the same in the code.
Can someone guide me please for the above-mentioned.
Please run using the callme.m file.
With regards,
rc

採用された回答

Vilém Frynta
Vilém Frynta 2023 年 5 月 8 日
hi,
i took a peek at your code and it's massive. therefore i came just to say that if you have a value, where you only want the positive values, you can do this:
a = -5:1:5; % numbers from -5 to 5
idx = a > 0; % logical vectors, where the values are positive
a(idx) % vector 'a', where the values are positive
ans = 1×5
1 2 3 4 5
p.s.
if you really want help, it's a good practice to copy-paste your code here, as it's easier to access compared to downloading the files, opening them in Matlab and running it.
  3 件のコメント
Rahul
Rahul 2023 年 5 月 9 日
Can you plz advice how to implement it only in column 3 of my matrix?
with regards
Vilém Frynta
Vilém Frynta 2023 年 5 月 9 日
Depends on the position of the columns, but I'll show you.
Also, please, accept my answer if it was useful for you.
% Random 5×5 matrix
a = randi(10, [5 5])
a = 5×5
10 4 9 3 7 4 9 8 1 2 8 10 2 6 5 2 8 4 5 1 10 10 3 7 6
% Find where values are higher than 5 in the first 3 columns
idx = a(:,1:3) > 5
idx = 5×3 logical array
1 0 1 0 1 1 1 1 0 0 1 0 1 1 0
% Apply index to the matrix
a(idx)
ans = 9×1
10 8 10 9 10 8 10 9 8

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

その他の回答 (1 件)

E. Cheynet
E. Cheynet 2023 年 5 月 9 日
Rather than restricting the turbulence intensities to positive values only, I suggest to understand why the turbulence intensity is sometimes negative. Per definition, it should not happen. So there may be something wrong in the code.
  2 件のコメント
Rahul
Rahul 2023 年 5 月 9 日
May be its a numerical error in pdepe solver?
E. Cheynet
E. Cheynet 2024 年 2 月 26 日
The error comes likely from the function that calculate the turbulence intensity.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by