Gradient of a surface

조회 수: 10 (최근 30일)
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2018년 1월 3일
답변: Walter Roberson 2018년 1월 3일
Hi all,
I have written the following code in order to determine the gradient of a function between certain X and Y values specified by the X and Y values limits of the graph I am plotting.
K = 273.15 ; %constant
[x, y] = meshgrid(1.4:0.1:5,70:5:200) ; %x & y values
z = (x.^(0.4/1.4) - 1) ./ ( (y + K)/(25 + K) - 1) ; %function
[Fx, Fy] = gradient(z) ; %gradient of the function
figure
contour(x, y, z, [0:0.1:1], 'ShowText', 'on')
ax = gca ;
ax.XLim = [1.4, 5] ;
ax.YLim = [70, 200] ;
grid on
xlabel('Pressure Ratio (-)')
ylabel('Temperature (degC)')
Howver, when I try to plot the Fx and Fy, the plot comes out to be blank. Therefore, how do i find the gradient of the function between the desired X & Y values?
Thanks for your help in advance,
KMT.

채택된 답변

Walter Roberson
Walter Roberson 2018년 1월 3일
>> max(Fx(:))
ans =
0.145210103674753
>> min(Fx(:))
ans =
0.0155307058204656
>> max(Fy(:))
ans =
-0.00505640320134679
>> min(Fy(:))
ans =
-0.386812925230569
The gradient is the change in values. It is to be expected that the change in values is often less than the range of values that you happen to be plotting. If you stick with the contour interval 0:.1:1 then only the 0.1 level has any data for Fx, and none of the Fy is in the range 0 to 1 so if you use 0:0.1:1 then as your level list then you would expect a blank plot.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by