1
$\begingroup$

Pre-amble OK, I'm fairly new to Mathematica. I've covered things like integration, partial differentiation, and plotting basic graphs. I'm now moving into Metric Spaces. I've had a search around for a guide/handout/book for plotting open/closed balls and spheres without any success. I have managed very basic plots with the help or one or two posts here - thanks for that - but here are some examples of what I'm hoping to be able to do.

Question Using Mathematica Desktop, how can I plot open Bd((0,0),1), closed Bd[(0,0),1] balls and spheres Sd((0,0),1) for metrics such as:

d((x1,x2),(y1,y2)) = |y1 - x1| + 3|y2 - x2|

d((x1,x2),(y1,y2)) = 4|y1 - x1| + d0(x2,y2)

If you've covered metric spaces, you'll know that an open ball doesn't include the points at the outermost edges (hence it should have a dotted line); a closed ball includes the points at the outermost edges (hence a solid line); and a sphere is just the points at the outermost edges. These are not just drawing a Ball or Sphere using {x,y,z}.

This post has some good information on plotting open balls but I'd appreciate some help with how to define the metrics shown above then plotting the associated balls. Plotting open balls for the given metric spaces

Thanks for any help you can give

$\endgroup$
4
  • $\begingroup$ Try RegionPlot or ContourPlot. For open balls, just set the style of the boundary lines to None. $\endgroup$ Commented Mar 10, 2022 at 11:42
  • $\begingroup$ Henrik, thanks. Yes, RegionPlot is the way to go with producing the plot. Any help with defining the metric, the d[] command? $\endgroup$ Commented Mar 10, 2022 at 11:51
  • $\begingroup$ The second metric would be f = Function[{x, y}, 4 Abs[Indexed[x, 1] - Indexed[y, 1]] + Unitize[Indexed[x, 2] - Indexed[y, 2]]], wouldn't it? The balls are indeed not easy to plot. For radius $<1$, the closed balls are horizontal line segments; you could draw the with the Line primitive. For radius $\geq 1$ the closed ball would be the region between two vertical lines, the lines included. You could use the primitive Rectangle to visualize thoses. $\endgroup$ Commented Mar 10, 2022 at 13:41
  • $\begingroup$ That second metric could well work, Henrik. I just need to find out how to plot it, whether using Line, Rectangle or otherwise. Thank you for the help you've provided. $\endgroup$ Commented Mar 10, 2022 at 14:05

1 Answer 1

2
$\begingroup$
f = Function[{x, y}, Abs[Indexed[x, 1] - Indexed[y, 1]] + 3 Abs[Indexed[x, 2] - Indexed[y, 2]]];

Closed ball:

RegionPlot[f[{x, y}, {0, 0}] <= 1, {x, -1, 1}, {y, -1, 1}, 
 PlotPoints -> 100
 ]

Open ball:

RegionPlot[f[{x, y}, {0, 0}] <= 1, {x, -1, 1}, {y, -1, 1}, 
 PlotPoints -> 100,
 BoundaryStyle -> None
 ]

Spehere:

ContourPlot[f[{x, y}, {0, 0}] == 1, {x, -1, 1}, {y, -1, 1}, 
 PlotPoints -> 100
 ]
$\endgroup$
3
  • $\begingroup$ Excellent! Many thanks for this. This works perfectly for the first metric. Do you have any thoughts on the second metric involving the discrete metric d0? $\endgroup$ Commented Mar 10, 2022 at 11:58
  • $\begingroup$ Syntax::sntxf: "{x,y}|" cannot be followed by "->Abs[Indexed[x,1]-Indexed[y,1]]+3Abs[Indexed[x,2]-Indexed[y,2]]". this make me confusing but at least in version 11 gives error $\endgroup$ Commented Mar 10, 2022 at 12:40
  • $\begingroup$ @AnxonPués Ah yes, the |-> syntax was only added recently. $\endgroup$ Commented Mar 10, 2022 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.