Contour plots for random variables
4 views (last 30 days)
Show older comments
Hi everybody,
I am trying to plot contours for variable "T". T itself is a function of X and Y. Below is my code, which is clearly wrong!
clc
clear all
X = gevrnd(-0.4176,0.6703,1.4837,100000,1); %X follows GEV distribution
Y = gprnd(-0.0960,0.2152,1.7001,100000,1); %Y follows GPD distribution
U = cdf('generalized extreme value',X,-0.4176,0.6703,1.4837);
V = cdf('Generalized Pareto',Y,-0.0960,0.2152,1.7001);
C = exp(1-((((1-log(U)).^0.9838-1).^1.0075+((1-log(V)).^0.9838-1).^1.0075).^0.9926+1).^1.0165); % Copula
% Return period: T = mu / (1+C-U-V)
mu = 0.08;
T = @(U,V) mu./(1+C-U-V);
fc = fcontour(T,U,V)
fc.LevelList = [1 5 10 25]; %Joint contours for T = 1; 5; 10 and 25 years
How shouhd I do this?
0 Comments
Answers (1)
per isakson
on 3 Jan 2020
Edited: per isakson
on 3 Jan 2020
Specify a function of the form z = f(x,y). The function must accept two matrix input arguments and return a matrix output argument of the same size.
The vector C is the problem
>> T = @(U,V) mu./(1-U-V);
>> fcontour( T, [2.5,3.5,1.8,3.2] )
produces a plot without throwing an error.
Try this script
%%
Z = T(U,V);
Finterp = scatteredInterpolant( X, Y, Z );
xmin = 2.5; % min(X);
xmax = 3.5; % max(X);
ymin = min(Y);
ymax = max(Y);
N = 1000;
xrange = linspace(xmin, xmax, N);
yrange = linspace(ymin, ymax, N);
[XGrid, YGrid] = meshgrid(xrange, yrange);
ZGrid = Finterp(XGrid, YGrid);
contourf(XGrid, YGrid, ZGrid);
xlabel('X');
ylabel('Y');
zlabel('T');
ZGrid and pieces thereof may also be displayed as an image
imagesc(ZGrid(1:100,:))
Replace
contourf(XGrid, YGrid, ZGrid);
by
contourf( XGrid, YGrid, ZGrid, 64 );
to get a higher resolution in ZGrid
See Also
Categories
Find more on Visual Exploration 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!