Borrar filtros
Borrar filtros

Writing a code to determine the gradient change in a profile

31 visualizaciones (últimos 30 días)
Rahul
Rahul el 28 de Jun. de 2024 a las 2:59
Editada: Rahul el 29 de Jun. de 2024 a las 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

Respuesta aceptada

John D'Errico
John D'Errico el 28 de Jun. de 2024 a las 7:25
Editada: John D'Errico el 28 de Jun. de 2024 a las 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 comentario
Rahul
Rahul el 28 de Jun. de 2024 a las 14:41
Editada: Rahul el 29 de Jun. de 2024 a las 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

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by