Gradient of a surface
9 views (last 30 days)
Show older comments
Konstantinos Tsitsilonis
on 3 Jan 2018
Answered: Walter Roberson
on 3 Jan 2018
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.
0 Comments
Accepted Answer
Walter Roberson
on 3 Jan 2018
>> 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 Comments
More Answers (0)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!