How to plot this functions for linear programming

I have this functions, and I want to plot them on same page because this is a problem in linear programing and I want to show both on same graph.
First is: f = x+0.0625*x^2 + y+0.0125*y^2 + z+0.025*z^2 (this is objective function)
Second is: g=x+y+z-952 (this is boundary)
Thanks!

4 commentaires

Is one of the variables, x or y or z, being held as a constant? If not then you would be trying to plot in 4 dimensions, (x, y, z, f) which is going to be a problem.
Danijel
Danijel le 22 Jan 2013
Since I solved the problem with Lagrange method, I have the values for x,y,z, and λ - Lambda (the Lagrange multiplier). Maybe this could be useful... The solved values are: x=112; y=560; z=280; λ=15
Are you asking to plot a single point, f(112,560,280) ??
If you are wanting to plot f over a range of values of x, and a range of values for y, and a range of values for z, then you need x, y, and z graphic axes to represent the inputs, but you also need another graphics axis to represent the result f(x,y,z) -- a 4 dimensional plot. Is that what you were thinking of?
Danijel
Danijel le 22 Jan 2013
The second approach would be something what I was thinking of. I tried to plot the first function with isosurface, but I'm not sure wether this is truth what I'm getting as a result, because as I don't know which value for isovalue to set? Also, I don't know how to plot the g function on the same page...
[x,y,z] = meshgrid( linspace( -120, 600, 300 ) ); f = x+0.0625*x.^2 + y+0.0125*y.^2 + z+0.025*z.^2; isosurface(x, y, z, f, 476)

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 22 Jan 2013
Modifié(e) : Matt J le 22 Jan 2013
Since the solution has to satisfy
x+y+z=952
why not eliminate one of the variables, e.g.
h(x,y) = f(x,y,952-x-y)
and plot the 2D surface h(x,y) only? Why care about any other region?
BTW, your objective function is quadratic, so I'm not sure why you call this a "linear programming problem"

10 commentaires

Danijel
Danijel le 22 Jan 2013
"BTW, your objective function is quadratic, so I'm not sure why you call this a "linear programming problem"" That's truth...
Danijel
Danijel le 22 Jan 2013
I am not sure about this h(x,y). I will try. Thanks.
Danijel
Danijel le 22 Jan 2013
I tried, but the plot is strange. It's not giving the qudratic function.
Anyone? Help please?
Matt J
Matt J le 22 Jan 2013
Help with what? How can we find your bugs if you don't show your code?
Danijel
Danijel le 22 Jan 2013
Modifié(e) : Danijel le 22 Jan 2013
This is the solution and the plot of the function I tried to plot:
syms x y z Lambda f=x+0.0625*x^2+y+0.0125*y^2+z+0.025*z^2 g=x+y+z-952 L=jacobian(f,[x y z])-Lambda*jacobian(g,[x y z]) [Lambdasoln,xsoln,ysoln,zsoln]=solve(L,g) [x,y,z] = meshgrid( linspace( -120, 600, 300 ) ); f = x+0.0625*x.^2 + y+0.0125*y.^2 + z+0.025*z.^2; isosurface(x, y, z, f, 476)
I tried with the 2D plot also but it gives the surface, and since it is quadratic, something's wrong...
How about
[x,y] = meshgrid( linspace( -120, 600, 300 ) );
f =@(x,y,z) x+0.0625*x.^2 + y+0.0125*y.^2 + z+0.025*z.^2;
h= f(x,y,952-x-y);
surf(x,y,h)
Danijel
Danijel le 22 Jan 2013
Modifié(e) : Danijel le 22 Jan 2013
Thanks Matt J. That's great...
Also, if you know, can Matlab show the Lagrange solution in any way?
Matt J
Matt J le 24 Jan 2013
What is "the Lagrange solution"?
Danijel
Danijel le 8 Fév 2013
Sorry Matt J. I didn't see your answer. The Lagrange solution is x=112; y=560; z=280; λ=15
Matt J
Matt J le 8 Fév 2013
You can use the TEXT command to add annotation to plots

Connectez-vous pour commenter.

Catégories

Produits

Question posée :

le 22 Jan 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by