필터 지우기
필터 지우기

Writing a code to determine the gradient change in a profile

조회 수: 5 (최근 30일)
Rahul
Rahul 2024년 6월 28일
편집: Rahul 2024년 6월 29일
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일
편집: John D'Errico 2024년 6월 28일
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일
편집: Rahul 2024년 6월 29일
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 CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by