i have a cone, which is described as in the figure:
(two bases are ellipses)
How can i plot the surface by Mathematica?
You could always use a RegionPlot:
RegionPlot3D[ Sqrt[x^2 + y^2] < 1 - z/3, {x, -2, 2}, {y, -2, 2}, {z, -1, 1},
BoxRatios -> {1, 1, 1/2}]
Related
There is a certain parameter values set over a regular 2D lattice. I want to display them in the form of cells of a regular grid, filled in with a color depending of the value of the parameter. There may be gaps in individual grid nodes. Here is an example of the data and the desired result of plotting:
a = [1, 2, 3, 1, 2, 3, 1, 2]
b = [1, 1, 1, 2, 2, 2, 3, 3]
c = [1, 5, 4, 3, 4, 2, 1, 3]
plot(a, b, zcolor = c, aspect_ratio = 1, xlim = (0.5, 3.5), ylim = (0.5, 3.5), clim = (0, 5),
seriestype = :scatter, markersize = 82, markershape = :square, markerstrokewidth = 0.5,
legend = false, colorbar = true)
This approach works, but in this case, is needed to adjust the size of the squares each time so that there are no gaps between the cells and they do not run over each other. This requires constant manual intervention and does not look like the right solution. What is the most correct approach in this case? I thought about heatmap(), but as far as I understand, in Julia it does not know how to display cell borders. Perhaps there is some way to set in plot() the icon sizes in absolute canvas units? Or is it better to use some other approach for such situations?
heatmap seems like the way to go to me. If your a and b spanned the entire lattice, I would just use reshape to, well, reshape c. This is not your case here, so one solution is to fill the lattice with NaNs where you have no value. E.g.,
using Plots
a = [1, 2, 3, 1, 2, 3, 1, 2]
b = [1, 1, 1, 2, 2, 2, 3, 3]
c = [1, 5, 4, 3, 4, 2, 1, 3]
x, y = sort(unique(a)), sort(unique(b)) # the lattice x and y
C = fill(NaN, length(y), length(x)) # make a 2D C with NaNs
for (i,j,v) in zip(a,b,c) # fill C with c values
C[j,i] = v
end
heatmap(x, y, C, clims=(0,5)) # success!
gives
EDIT: If you want to specify the edges of the cells, you can do this with heatmap, and if you want lines, you can add them manually I guess, for example with vline and hline?
ex, ey = [0, 1.5, 2.3, 4], [0.5, 1.5, 2.5, 3.5]
heatmap(ex, ey, C, clims=(0,5))
vline!(ex, c=:black)
hline!(ey, c=:black)
will give
Is it possible to plot two implicit functions on the same canvas with sympys plot_implicit function?
E.g. have both lines from the two plots in the example be shown on one canvas.
from sympy import *
x,y = symbols('x y')
init_printing()
plot_implicit(Eq(abs(x)+abs(y), 1), (x,-1,1), (y, -1,1))
plot_implicit(Eq(x**2 + y**2, 1), (x,-1,1), (y, -1,1))
To combine two plots with sympy's plotting, the plots are first created with show=False, then appended and ultimately shown:
from sympy import symbols, plot_implicit, Eq, Abs
x, y = symbols('x y')
plot1 = plot_implicit(Eq(Abs(x) + Abs(y), 1), (x, -1, 1), (y, -1, 1),
line_color='steelblue', show=False)
plot2 = plot_implicit(Eq(x ** 2 + y ** 2, 1), (x, -1, 1), (y, -1, 1),
line_color='crimson', show=False)
plot1.append(plot2[0])
plot1.show()
I am trying to tell R that x should range from -10 to 10, and to plot the logistic function of x for this range of values; more specifically, I am trying to plot y=logistic(x)= 1/(1+exp(-x)).
This is in the context of stats homework that is teaching GLM in R.
This is what I did to define x:
x <- c(-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Then I tried this:
glm(formula= y ~ log(x))
and got
object 'y' not found
which confused me because y should just be defined based on the x-values I am specifying, right?
I'm feeling like this should be simple but just can't figure it out.
x <- -10:10
y <- 1/(1+exp(-x))
plot(x, y, type="l")
I guess it can be quite confusing in R, it goes like this, you define the function, which you have already done:
logistic = function(x)(1/(1+exp(-x)))
Then you can do:
curve(logistic,from=-10,to=10)
Or using plot, which calls curve anyway:
plot(logistic,from=-10,to=10)
I need to solve and plot the slope field for the equation y'=cos(y)-1.
DSolve[{y'[x] == -1 + Cos[y[x]]}, y[x], x]
VectorPlot[{1, (-1 + Cos (y))}, {x, -3, 3}, {y, -3, 3}]
I get an empty graph. Any help?
As suggested in the comment, you are suppose to use Cos[] not Cos() in Mathematica.
You can solve the ode and combine the VectorPlot with the solution curves like this
soln[y0_?NumericQ] :=First#DSolve[{y'[x] == -1 + Cos[y[x]], y[0] == y0}, {y}, {x, 0,10}];
vp = VectorPlot[{1, (-1 + Cos[y])}, {x, -3, 3}, {y, -3, 3}];
Show[vp, Plot[
Evaluate[{y[x]} /. soln[#] & /# Range[-20, 20, 0.3]], {x, -3, 3},
PlotRange -> All, MaxRecursion -> 8, AxesLabel -> {"x", "y"}]]
Is it possible to plot a function in Mathematica without isolating y first?
Something like this:
Plot[2*x + y == 2, {x, -10, 10}]
ContourPlot[2*x + y == 2, {x, -10, 10}, {y, -10, 10}]
https://reference.wolfram.com/mathematica/ref/ContourPlot.html