%Gravityfield.m %Steven Sahyun, November 9, 2015 %University of Wisconsin Physics Dept. %sahyuns@uww.edu %Creates a graph of a gravity field useful for plotting to a 3D printer clear; clf(); xmax=200; ymax=200; x = 1:1:xmax; y = 1:1:ymax; xcenter = 100; ycenter = 100; meshgrid(x,y); % Make a blank matrix x0 = 1+0*x; y0 = 1+0*y; z = x0'*y0; % General equation for gravitational potential % U(r) = -m1m2G/r m1 = 20; %BH mass m2 = 1; %test mass G = 1; zoffset = 0; % Set the gravitational potential for each matrix grid element. for m = 1:xmax for n = 1:ymax z(m,n) = z(m,n)*((2-(m1*m2*G)/sqrt(abs(x(m)-xcenter)^2+(abs(y(n)-ycenter)^2))))-zoffset; if z(m,n) < 0.1 % If potential goes below 0, set value to 0; this can be considered the Schwartzchild radius. z(m, n) = 0; end end end zscale = 20; %this is to set the z-axis scale to have a good plot, 10x10x2 z = z*zscale; %Plot the surface surf(x,y,z); %convert to a 3D printable file; You need to have stlwrite.m and surf2solid.m by %Sven Holcombe in the same directory as this file. %See: http://jmumakerlab.blogspot.com/2013/11/exporting-stl-from-matlab.html % http://www.mathworks.com/matlabcentral/fileexchange/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing % http://www.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin- %functions Gravityfield = surf2solid(x, y, z, 'Elevation', 0); stlwrite('Gravityfield.stl',Gravityfield)