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.
Related
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.
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)
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.
I used polyfit to find the best fit through my X and Y data.
p = polyfit(x,y,4)
After that I used polyval to make a line with the polyfit with other X data
a = [-5 : 0.1 : 15]
line = polyval(p,a)
When I plot this line and when I look at the data, I see that it has intersections with the x-axis. But there is not an exact y=0
My question is, how do I find the (there are 2) intersection points with the x-axis, or atleast the x where y is the closest to 0?
Thanks in advance!
First, don't use line as a variable name, it is a MATLAB function you are shadowing and won't be able to access.
p = polyfit(x,y,4);
a = [-5 : 0.1 : 15];
b = polyval(p,a);
To get the intersection with the x axis, you are essentially looking for the roots of the polynomial, i.e. when y=0 and there is a function just for that:
r = roots(p);
How can I graph multiple functions on the same graph/plot/Cartesian plane on MATLAB with domain and range restrictions?
For example I made up the following functions below. How would I graph the following on the same graph within MATLAB?
Function 1: x = -3 for 10 <= y <= 14
Function 2: y = -2x for -5 <= x <= -4
Function 3: (x-0)^2 + (y-12)^2 = 2.25 // Produces a circle
Function 4: y = 4 for -1 <= x <= 1
Matlab is a numerical computing environment, so you'll need to tell it what you're looking for while plotting.
In the case of your first example, you'll need to tell it which Y values to plot. Since X is always the same, you know it's going to be a line - so two points will be enough. Plot requires parallel arrays, so:
Function 1: x = [-3 -3]; y = [10 14]; plot(x, y);
To plot additional lines on the same graph, use the command hold on, which applies to the figure you just plotted. If you don't do this, new plot commands will erase the old plots.
Similarly,
Function 2: x = [-5 4]; y = -2*x; plot(x, y);
For circles/ellipses like #3, ezplot can be helpful, although you still have to specify the range.
Function 3: ezplot('x^2 + (y-12)^2 - 2.25', [-3,3,10,14])
The last one is easy, but let's say it were a curve instead. You'd want to plot more than just two x values. You can create a vector from a range like this: x = -1:0.1:1;, or an evenly space set of points from -1 to 1, with an interval of 0.1. Let's say you want to plot it on the same graph, and you've already done hold on. You want a different color, and you want to show the individual points that make up the line, you can use the third argument to the plot function:
Function 4: x = -1:0.1:1; y = 4 * ones(length(x)); plot(x, y, '-r.');
The second command here, y = 4 * ones(length(x)); simply creates a y vector that is the same length as x.