Putting two plots in a manipulate whilst keeping the plots visible - wolfram-mathematica

I want to look at both the real and imaginary parts of some functions that depend on a parameter n. Individually (with set values of n), I get perfectly nice graphs, but when putting them in a Manipulate they become very small.
Here is the exact code I'm using; remove the manipulate and the graphs display at a good size, but with it they are too small to be legible.
Manipulate[
Plot3D[Im[Sqrt[-1 + (x + I y)^2 n]], {x, -2, 2}, {y, -1, 1},
AxesLabel -> Automatic]
Plot3D[Re[Sqrt[-1 + (x + I y)^2 n]], {x, -2, 2}, {y, -2, 2},
AxesLabel -> Automatic]
, {n, 1, 10, 1}]
Why is it doing this, and how can I fix it?

Manipulate[
Row[{
Plot3D[Im[Sqrt[-1 + (x + I y)^2 n]], {x, -2, 2}, {y, -1, 1},
AxesLabel -> Automatic, ImageSize -> 300] ,
Plot3D[Re[Sqrt[-1 + (x + I y)^2 n]], {x, -2, 2}, {y, -2, 2},
AxesLabel -> Automatic, ImageSize -> 300]}],
{n, 1, 10, 1}]
Edit
Remember that you may also do something like:
a = Sequence ##{{x, -2, 2}, {y, -1, 1}, AxesLabel-> Automatic, ImageSize-> 200};
Manipulate[
Row[{
Plot3D[Im[Sqrt[-1 + (x + I y)^2 n]], Evaluate#a],
Plot3D[Re[Sqrt[-1 + (x + I y)^2 n]], Evaluate#a]}],
{n, 1, 10, 1},
PreserveImageOptions -> False]

Related

Working with implicit functions in Mathematica

Can I plot and deal with implicit functions in Mathematica?
for example :-
x^3 + y^3 = 6xy
Can I plot a function like this?
ContourPlot[x^3 + y^3 == 6*x*y, {x, -2.7, 5.7}, {y, -7.5, 5}]
Two comments:
Note the double equals sign and the multiplication symbols.
You can find this exact input via the WolframAlpha interface. This interface is more forgiving and accepts your input almost exactly - although, I did need to specify that I wanted some type of plot.
Yes, using ContourPlot.
And it's even possible to plot the text x^3 + y^3 = 6xy along its own curve, by replacing the Line primitive with several Text primitives:
ContourPlot[x^3 + y^3 == 6 x y, {x, -4, 4}, {y, -4, 4},
Background -> Black, PlotPoints -> 7, MaxRecursion -> 1, ImageSize -> 500] /.
{
Line[s_] :>
Map[
Text[Style["x^3+y^3 = 6xy", 16, Hue[RandomReal[]]], #, {0, 0}, {1, 1}] &,
s]
}
Or you can animate the equation along the curve, like so:
res = Table[ Normal[
ContourPlot[x^3 + y^3 == 6 x y, {x, -4, 4}, {y, -4, 4},
Background -> Black,
ImageSize -> 600]] /.
{Line[s_] :> {Line[s],
Text[Style["x^3+y^3 = 6xy", 16, Red], s[[k]], {0, 0},
s[[k + 1]] - s[[k]]]}},
{k, 1, 448, 3}];
ListAnimate[res]
I'm guessing this is what you need:
http://reference.wolfram.com/mathematica/Compatibility/tutorial/Graphics/ImplicitPlot.html
ContourPlot[x^3 + y^3 == 6 x*y, {x, -10, 10}, {y, -10, 10}]

How to shade a plot in Mathematica

I want to generate a plot like the following
I am not sure how to generate a shading even though I can get the frame done. I'd like to know the general approach to shade certain areas in a plot in Mathematica. Please help. Thank you.
Perhaps you are looking for RegionPlot?
RegionPlot[(-1 + x)^2 + (-1 + y)^2 < 1 &&
x^2 + (-1 + y)^2 < 1 && (-1 + x)^2 + y^2 < 1 && x^2 + y^2 < 1,
{x, 0, 1}, {y, 0, 1}]
Note the use of op_ in the following (only one set of equations for the curves and the intersection!):
t[op_] :=Reduce[op[(x - #[[1]])^2 + (y - #[[2]])^2, 1], y] & /# Tuples[{0, 1}, 2]
tx = Texture[Binarize#RandomImage[NormalDistribution[1, .005], 1000 {1, 1}]];
Show[{
Plot[y /. ToRules /# #, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}] &# t[Equal],
RegionPlot[And ## #, {x, 0, 1}, {y, 0, 1}, PlotStyle -> tx] &# t[Less]},
Frame->True,AspectRatio->1,FrameStyle->Directive[Blue, Thick],FrameTicks->None]
If, for any particular reason, you want the dotted effect in your picture, you can achieve this like so:
pts = RandomReal[{0, 1}, {10000, 2}];
pts = Select[pts,
And ## Table[Norm[# - p] < 1, {p,
{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}] &];
Graphics[{Thick,
Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}],
Circle[{0, 0}, 1, {0, Pi/2}],
Circle[{1, 0}, 1, {Pi/2, Pi}],
Circle[{1, 1}, 1, {Pi, 3 Pi/2}],
Circle[{0, 1}, 1, {3 Pi/2, 2 Pi}],
PointSize[Small], Point[pts]
}]

Plot, plane, point, line, sphere in same 3D plot. Multiple figures in same plot in Mathematica

How do I plot for example a plane and a line in same 3D plot?
Show and Plot3D can handle it. There are probably many other ways.
l = Line[{{-2, -2, 41}, {6, 4, -10}}];
Show[{Plot3D[{2 x + 7 y}, {x, -2, 5}, {y, -2, 5}, AxesLabel -> {x, y, z}],
Graphics3D[{Thick, l}]}]
I couldn't resist either...
GraphicsGrid[
{
{ContourPlot3D[x + 2 y + 3 z , {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
Contours -> {0}, Axes -> None, ColorFunction -> (White &),
Lighting -> "Neutral"],
Style["One plane", FontFamily -> "Comic Sans MS", 36, Bold]},
{ContourPlot3D[x + 2 y + 3 z , {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
Contours -> {0, 5}, Axes -> None, ColorFunction -> (Green &),
Lighting -> "Neutral"],
Style["Two plane", FontFamily -> "Comic Sans MS", 36, Bold]},
{ContourPlot3D[x + 2 y + 3 z , {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
Contours -> {0}, Axes -> None, ColorFunction -> (Red &),
Lighting -> "Neutral"],
Style["Red plane", FontFamily -> "Comic Sans MS", 36, Bold]},
{Show[
ContourPlot3D[x + 2 y + 3 z , {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
Contours -> {0}, Axes -> None, ColorFunction -> (Blue &),
Lighting -> "Neutral"],
Graphics3D[{Orange, Thickness[0.01],
Line[{{-2, -2, -2}, {2, 2, 2}}]}]
], Style["Blue plane", FontFamily -> "Comic Sans MS", 36, Bold]}
}
]
Just showing off:
Manipulate[
Show[
{Plot3D[ {1}, {x, -1, 1}, {y, -1, 1}, PlotRange -> {-1, 1}, Mesh -> False],
Plot3D[{-1}, {x, -1, 1}, {y, -1, 1}, Mesh -> False],
ParametricPlot3D[{{Sin#t, Cos#t, 1}, {Sin#t, Cos#t, -1}}, {t, 0, 2 Pi}],
Graphics3D[
{Table[{Hue[n/10], Thick, Line[{{Re[#], Im[#], 1}, {-z Re[#], -z Im[#], z}}&#
Exp[n 2 I Pi/10]]}, {n, 10}],
Sphere[{0, 0, 0}, .3]}]}],
{z, 1, -1}]

Using Boole with MaxValue and or PlotRegion

Why doesn't this work?
I have bypassed this before but i can't remember how i did it, and I never went on to figure out why this type of inputs didn't work. About time to get to know it!
For those who cant see the pic:
RegionPlot3D[
x^2 + 2 y^2 - 2 z^2 = 1 && -1 <= z <= 1, {x, -5, 5}, {y, -5,
5}, {z, -1, 1}]
Set::write: "Tag Plus in -2.+25.+50. is Protected"
And then there is just an empty cube without my surface.
If z is limited by other surfaces you could go like this:
RegionPlot3D[
x^2 + 2 y^2 - 2 z^2 < 1 && z < x + 2 y && z^2 < .5,
{x, -2, 2}, {y, -2, 2}, {z, -1, 1},
PlotPoints -> 50, MeshFunctions -> {Function[{x, y, z}, z]},
PlotStyle -> Directive[Red, Opacity[0.8]]]
Or with ContourPlot:
ContourPlot3D[
x^2 + 2 y^2 - 2 z^2 == 1,
{x, -2, 2}, {y, -2, 2}, {z, -1, 1},
RegionFunction -> Function[{x, y, z}, z < x + 2 y && z^2 < .5],
PlotPoints -> 50, MeshFunctions -> {Function[{x, y, z}, z]},
ContourStyle -> Directive[Red, Opacity[0.8]]]]
Try this
RegionPlot3D[x^2 + 2 y^2 - 2 z^2 < 1,
{x, -5, 5}, {y, -5, 5}, {z, -1, 1}]
Or, if you just want the surface
ContourPlot3D[x^2 + 2 y^2 - 2 z^2 == 1,
{x, -5, 5}, {y, -5, 5}, {z, -1, 1}]
Note the double equals sign, rather than the single equals sign.

Setting all points of a given ListPlot with a given color in Mathematica

How can I make it such that plotting the following function
ListPointPlot3D[points, PlotStyle -> PointSize[0.05]];
the points I see are green or yellow, for instance, instead of the typical dark blue ones?
Thanks
Use Directive to combine styles, ie
ListPointPlot3D[points, PlotStyle -> Directive[{PointSize[0.05], Green}]]
Edit I give you below two possible solutions in a context related to your previous question. Nevertheless, please note that #Yaroslav's code is much better.
f[x_, y_] := x^2 + y^2;
t = Graphics3D[{PointSize[Large], Red, Point#
Flatten[Table[{x, y, f[x, y]}, {x, 0, 10, 1}, {y, 1, 2, 1}], 1]}];
b = Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10},
ColorFunction -> "MintColors"];
Show[{b, t}]
Or
f[x_, y_] := x^2 + y^2;
points = Flatten[Table[{x, y, f[x, y]}, {x, 0, 10, 1}, {y, 1, 2, 1}],
1];
a = ListPointPlot3D[points,
PlotStyle -> Table[{Red, PointSize[0.05]}, {Length#t}]];
b = Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10},
ColorFunction -> "MintColors"];
Show[{b, a}]
Sometimes I find the following approach useful, as it allows me to
manipulate the plot symbol (PlotMarkers does not seem to work with ListPointPlot3D,
at least in Mathematica 7) [originally suggested by Jens-Peer Kuska]:
ListPointPlot3D[{{1,1,1},{2,2,2},{3,3,3}}]/.Point[xy_]:>(Style[Text["\[FilledUpTriangle]",#],Red,FontSize-> 20]&/#xy)

Resources