NM-Solved(How to plot points from a Maximize[ ] output)

Click For Summary
SUMMARY

This discussion focuses on extracting numerical values from the output of the Maximize function in Mathematica. The output format includes both the maximum value and a list of variable assignments, such as {21.0133, {b -> 1, c -> -3., d -> 2., e -> 3, f -> 4}}. The user seeks a method to reference these values programmatically to create a list plot. A solution involves assigning the output to a variable and using the replacement operator (/.), allowing for direct plotting of the values without manual entry.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of the Maximize function in Mathematica
  • Knowledge of list manipulation in Mathematica
  • Basic concepts of plotting in Mathematica
NEXT STEPS
  • Learn how to use the Maximize function in Mathematica effectively
  • Explore list manipulation techniques in Mathematica
  • Study the replacement operator (/. ) in Mathematica
  • Investigate plotting functions in Mathematica for visual data representation
USEFUL FOR

Mathematica users, data analysts, and anyone interested in automating data extraction and visualization from optimization outputs.

Wesleytf
Messages
31
Reaction score
0
NM-Solved(How to plot points from a "Maximize[ ]" output)

Hello all,

I'm working with some data sets and I want to make a bar-type graph out of the numbers that result after a series of equations ending in a maximize function. My trouble is that the output of the function gives something like

Code:
{21.0133, {b -> 1, c -> -3., d -> 2., e -> 3, f -> 4}}

How can I reference these numbers without having to manually enter them? I want to make a list plot out of them where each value corresponds to x coordinates 1, 2..., so I need them in a list {1, -3, 2, 3, 4}. Any ideas?

edit: I think I can solve this by flipping the equation and using linear programming. No need to reply, but thanks for looking.
 
Last edited:
Physics news on Phys.org


The way I would do it is assign that solution to a variable, like this

Code:
solution = Maximize[...]

Then, you can apply this as you see fit. Here is an example:

Code:
Plot[function[a,b,c] /. solution[[2]]]

The /. tells Mathematica to replace the arguments of function[] with the values of a,b,c from solution.

You use solution[[2]] because the second element of solution is the values of the variables.
 


Wesleytf said:
Code:
{21.0133, {b -> 1, c -> -3., d -> 2., e -> 3, f -> 4}}

How can I reference these numbers without having to manually enter them?

myaray = {b -> 1, c -> -3., d -> 2., e -> 3, f -> 4}

#[[2]] & /@ myaray
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K