フィルターのクリア

Writing a code to determine the gradient change in a profile

31 ビュー (過去 30 日間)
Rahul
Rahul 2024 年 6 月 28 日 2:59
編集済み: Rahul 2024 年 6 月 29 日 4:00
Hi,
I'm trying to write a code which can determine the gradient change in a given profile. However the code is unable to determine the same correctly and giving incorrect results. For the pic1 below it should give me the width of the region where it is a steep gradient determined.
However for pic2 below it shouldn't as there is no steep gradient compared to pic1
The code is as below:
clear width;
global width;
global data;
for i=1:max(length(data.variable.t))
for j=1:max(length(data.variable.x))-1
change_p = (abs(data.variable.gradpressure(i,j+1))-abs(data.variable.gradpressure(i,j)))/abs(data.variable.gradpressure(i,j));
%disp(change_p)
if change_p > 0.1
disp("steep gradient found")
width(j)=1-data.variable.x(j);
disp(width)
else
disp("no steep gradient found")
end
end
end
the data.variable.gradpressure is a 1000x100 matrix with t along the vertical and x along the horizontal.
with regards,
rc

採用された回答

John D'Errico
John D'Errico 2024 年 6 月 28 日 7:25
編集済み: John D'Errico 2024 年 6 月 28 日 7:25
Your problem lies in this line:
change_p = (abs(data.variable.gradpressure(i,j+1))-abs(data.variable.gradpressure(i,j)))/abs(data.variable.gradpressure(i,j));
You divide by one of the elements, apparently hoping to scale things, so that you can compare then to a simple unit-less value 0.1. But what happens when the denominator is very near to zero? Look at the numbers at the beginning of the curve!
  1 件のコメント
Rahul
Rahul 2024 年 6 月 28 日 14:41
編集済み: Rahul 2024 年 6 月 29 日 4:00
Hi John
Thanks a lot for pointing me out the errors.
I had some literature survey for gradient determination. I have seen some users applying 'quasi-Newton method'. May be I can also try it, although not sure if it can be applied in my case.
rgds,
rc

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by