plot - Matlab equivalent of Maple densityplot -


i create density plot of function:

enter image description here

in maple, 1 use densityplot function achieve (code @ end), gives:

density plot

however, not sure use plotting similar figure in matlab.

here current matlab code:

x = [0:10:100]; y = [-50:10:50]; s = [10, 0]; = [50,25]; ii = 1 : length(x)     sir(ii) = -10 * 9.8 * log10((power((x(ii) - s(1)),2) + power((y(ii) - s(2)),2)) / (power((x(ii) - i(1)),2) + power((y(ii) - i(2)),2)));   end 

could suggest equivalent in matlab?


for density plot in maple, used

densityplot(sir(x,y), x=0..100, y=-50..50, axes=boxed, style=patchnogrid, scaletorange=-5..50, colorscheme = [black, "green", "white"]) 

you can use surf (a 3d surface plot) achieve this, need finer grid steps of 10 good!

also need meshgrid combinations of x , y coordinates.

please see comments further details.

% set grid points x = 0:0.1:100; y = -50:0.1:50; [x,y] = meshgrid(x,y); % set parameters i, s , g = [50 25]; s = [10 0]; g = 9.8; % work out density   % - no need loop if use element-wise operations ./ , .^ % - power(z,2) replaced z.^2 (same function, more concise) % - forgot sqare roots in question's code, included using .^(1/2) % - line continuation "...", remove , have on 1 line sir = -10*g*log10( ((x-s(1)).^2 + (y-s(2)).^2).^(1/2) ./ ...                    ((x-i(1)).^2 + (y-i(2)).^2).^(1/2)        );  % plot, , set view above surf(x,y,sir,'edgecolor','none','facecolor','interp'); view(2); % change colour scheme colormap('bone') 

result:

plot

matching example

you used maple command scaletorange=-5..50. limits scale between -5 , 50 (docs), since sir our scale variable, should limit same. in matlab:

% restrict sir range [-5,50] sir = min(max(sir,-5),50); % of course have replot surf(x,y,sir,'edgecolor','none','facecolor','interp'); view(2); 

now, if wanted black/green colours, can use custom colormap, smooth out banding caused 'bone' colormap having 64 colours.

% define 3 colours interpolate between, , n interpolation points black = [0 0 0]; green = [0 1 0]; white = [1 1 1];  n = 1000;  % colour interpolation, equivalent maple's 'colorscheme = [black, "green", "white"]' % need nx3 matrix of colours (columns r,g,b), using interp1 colormap(interp1(1:3, [black; green; white], linspace(1,3,n))); 

with g=3.5 (not sure used), identical plot

compare


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -