Effacer les filtres
Effacer les filtres

Writing a code to determine the gradient change in a profile

31 vues (au cours des 30 derniers jours)
Rahul
Rahul le 28 Juin 2024 à 2:59
Modifié(e) : Rahul le 29 Juin 2024 à 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

Réponse acceptée

John D'Errico
John D'Errico le 28 Juin 2024 à 7:25
Modifié(e) : John D'Errico le 28 Juin 2024 à 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 commentaire
Rahul
Rahul le 28 Juin 2024 à 14:41
Modifié(e) : Rahul le 29 Juin 2024 à 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

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by