In Maple, how does one specify ranges for x,y, and t when using plot3d to plot a combination of parametric and Cartesian coordinate surfaces? - maple

Let's say I have a function $f(x,y) = 3x^2 + 5xy +2y^2$, a parametric line $ \langle 1+t, 2 - \frac{16t}{13}, 21 \rangle$, and a plane $z = f(x,y) = 21$, and I plot them:
f := (x, y) -> 3*x^2 + 5*y*x + 2*y^2
line := [1 + t, 2 - (16*t)/13, 21]
plot3d([21, line, f])
The docs for plot3d tell us:
The plot3d command computes the plot of a three-dimensional surface. The first two calling sequences describe surface plots in Cartesian coordinates, while the second two describe parametric surface plots.
I did not see examples of mixing up parametric with surface plots in Cartesian coordinates as I have above. The commands above work, but my question is how do I specify ranges for x, y, and t?

I found the answer in a book called "Understanding Maple", section 6.5 called "Combining Plots".
f := (x, y) -> 3*x^2 + 5*y*x + 2*y^2
line := [1 + t, 2 - (16*t)/13, 21]
plot3d([21, line, f])
with(plots):
p1 := plot3d(f):
p2 := plot3d(line):
p3 := plot3d(21):
display([p1, p2, p3])
display command, part of the plots package, is can be used to display two or more curves that use different coordinate systems. Note that in specifying $p1$ and $p2$ we can provide any options we want to customize those specific graphs, including specifying ranges for their variables.
You can also specify a "view" option on display to control the range displayed.

Related

Contour plotting a function in matlab over n levels

This script f = #(x,y) (1-x)^2 + 100*(y-x^2)^2; fcontour(f,[-2,2]);
draws the contours of the function, over the interval [-2,2]. Is it possible to display the contour lines over the levels 1,2,4,...2048, i.e over some v = 1:2:2048 ? The guide I found specifies how to do this for a matrix. Can I do this without replacing my function with some Z array ( The values of f on the interval )?

Could you explain why this matrix read as a scalar/vector when using surf? Also, is reshaping necessary? [duplicate]

I am attempting to plot 3D surfaces in MATLAB, and I made use of meshgrid, similar to what the MATLAB tutorials said here: http://www.mathworks.com/help/matlab/ref/meshgrid.html
I wrote a very simple three line script that I believed would produce the surface z = x + y and it is as follows:
[x , y] = meshgrid( linspace( 0 , 10 , 10 ) , linspace( 0 , 10 , 10 ) );
z = x + y;
surf( [ x , y , z] );
From what I understand, line 1 produces all combinations of (x,y) coordinates evenly spaced from 0 to 10. Then line 2 just applies the formula z = x + y to that exhaustive list of combinations. Then line 3 just plots all the (x, y, z) points.
But I got the following "thing" as output:
I'm pretty sure the graph in the above picture is not z = x + y, and I have no clue why there aren't two axes going up to maximum value 10.
Still, I find the script too simple and couldn't see anything wrong with it. Could anyone point out where I overlooked something? Thank you.
Your syntax for generating the 3D coordinates is right. Your call to surf is incorrect. What you actually need to do is separate x, y and z into three separate parameters:
surf(x,y,z);
When you do that, you get this surface. Take note that the figure generated was using MATLAB R2013a, so the colour map shown is not the parula colour map that is available as of R2014b and up, but the surface will be the right one that is what you're looking for:
... now why do you need to separate your x, y and z points to create the surface? The reason why is because doing [x,y,z] means that you are concatenating the x, y and z coordinates into a single 2D signal, and so what's happening is that you are creating a 2D signal that is 10 x 30. Calling surf with this single 2D array automatically assumes that the x values span from 1 to 30 and the y values span from 1 to 10 and those are the 2D grid of values that span the axis of your surf plot in conjunction with the z values shown, where the z values originate from the concatenated matrix created earlier. If you look at the plot you generated, you can see the x values are spanning from 1 to 30, and that's obviously not what you want.
You need to separate the x, y and z values to achieve the desired plane.

How to plot a parametric surface in Matlab

I have a parametric B-Spline surface, S
S=[x(:);y(:);z(:)];
Right now, I am plotting the surface by just plotting each column of S as a single point:
plot3(S(1,:),S(2,:),S(3,:),'.')
The result is this:
Unfortunately, by plotting individual points, we lose the sense of depth and curvy-ness when we look at this picture.
Any ideas on how to implement SURF or MESH command for a parametric surface? These functions seem to require a matrix representing a meshgrid which I dont think I can use since the X x Y domain of S is not a quadrilateral. However, I like the lighting and color interpolation that can be conveniently included when using these functions, as this would fix the visualization problem shown in figure above.
I am open to any other suggestions as well.
Thanks.
Without seeing your equations it's hard to offer an exact solution, but you can accomplish this by using fsurf (ezsurf if you have an older version of MATLAB).
There are specific sections regarding plotting parametric surfaces using ezsurf and fsurf
syms s t
r = 2 + sin(7*s + 5*t);
x = r*cos(s)*sin(t);
y = r*sin(s)*sin(t);
z = r*cos(t);
fsurf(x, y, z, [0 2*pi 0 pi]) % or ezsurf(x, y, z, [0 2*pi 0 pi])
If you want to have a piece-wise function, you can either write a custom function
function result = xval(s)
if s < 0.5
result = 1 - 2*s;
else
result = 2 * x - 1;
end
end
And pass a function handle to fsurf
fsurf(#xval, ...)
Or you can define x to be piece-wise using a little bit of manipulation of the function
x = (-1)^(s > 0.5) * (1 - 2*s)

plot Quadric Surfaces in General Form in matlab

I have Quadric Surface equation
I know A,B,C...
How can I plot my equation in matlab?
Your best bet is to produce a 3D contour plot of your function with a single contour at the function value 0. To do this with reasonable accuracy, compute your function F at a number of points x, y, z as follows:
gv = linspace(-30,30,50); % adjust for appropriate domain
[xx yy zz]=meshgrid(gv, gv, gv);
F = A*xx.*xx + B*yy.*yy + C*zz.*zz+ ... etc
figure
isosurface(xx, yy, zz, F, 0)
The reason to do it this way is that your function is typically multi-valued- that is, for a given value of X and Y there may be two possible answers for Z. By doing things this way you effectively bypass that problem - instructing matlab to put a surface anywhere that the function is zero.
Note that I gave an arbitrary vector gv for the grid - that is, the points on which the function is evaluated. To get an accurate and visually pleasing result you probably need around 50 points in each dimension within the range over which a solution is possible (this may be different in the three dimensions);
For example, with
F = xx.^2 + 2*yy.^2 + 0.5*zz.^2 + .4*xx.*yy + .5*xx.*zz + .6*yy.*zz + 7*xx + 8*yy + 9*zz - 100;
You get the following figure:

Plotting 3 inequations with 3 variables in maple

I need to plot this in maple
3x1+y+z<=180
x<=12
x+y+4z<=190
How can I do a plot in Maple? I'm using Maple 13
You plot inequalities with the inequal command from the plots library, and you can plot multiple equations by putting them in brackets:
plots[inequal]([3x1+y+z<=180, x<=12, x+y+4z<=190])
If a given plot command doesn't support multiple plots, you can always do the plots separately and combine them with display:
with(plots):
plot1 := inequal(3x1+y+z<=180):
plot2 := inequal(x<=12):
plot3 := inequal(x+y+4z<=190):
display([plot1, plot2, plot3])
Since you mentioned these three inequalities are constraints for an optimization problem, therefore I assume you are interested in the intersection of them and not each separately. Here is how I do it. I use piecewise command to define a binary values function that is equal to 1 when the point satisfies all three inequalities and then I use implicitplot3d command from plots package and an inequality f > 1/2 or you can go for the equality f = 1, then this command will plot the boundary of your region as a surface. Of course sometimes you may not get a suitable plot, for example one case happens when your region is tiny compared with the plotting box.
f := piecewise( And( 3*x + y + z <= 180, x <= 12, x + y + 4*z <= 190 ), 1, 0 );
plots:-implicitplot3d( f >= 1/2, x = -500..500, y=-300..700, z=-500..500, style = surface, grid = [50, 50, 50], color = blue, view = [-500..500, -300..700, -500..500 ] );
Here is the output.