Message Boards Message Boards

Use the numbers found in an optimization problem somewhere else?


Hello all, Let's say we solve maximization problem and create a table for a specific range. An example:

c1 = Table[NMaximize[{(x*y - y^2 + x - x^2)*a/2, 0 <= y <= x <= 1, a*(1 - y) <=  1}, {x, y}], {a, 1, 6, 0.1}]

Now resulting table have elements in a form such:

{0.166667, {x -> 0.666667, y -> 0.333333}

In order to solve another problem, I need to use these x and y values. How can I call them in a different place?

Best, Ovunc

p.s. I took the table to Excel, created three rows. I imported the Excel file into Mathematica, but this time I cannot convert it to the matrix form I am interested in.

POSTED BY: Ovunc Yilmaz
4 months ago

Welcome to Wolfram Community! Please make sure you know the rules:

The rules explain how to format your code properly. If you do not format code, it may become corrupted and useless to other members. Please EDIT your posts and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

enter image description here

POSTED BY: Moderation Team
4 months ago


you can reference the x and y variables with a replace.

Let's say you want the x value from the fifth result -- so take the second element from the fifth result (which is the list of x and y rules):

x /. c1[[5, 2]]

You can use this to restructure your results into a matrix:

lookupTable = Map[{#[[1]], x /. #[[2]], y /. #[[2]]} &, c1];

and look at it as a grid:

Grid[lookupTable , Frame -> All]

enter image description here

or export / use it.


POSTED BY: Neil Singer
4 months ago

Amazing! Thank you so much!

POSTED BY: Ovunc Yilmaz
4 months ago

Group Abstract Group Abstract