Message Boards Message Boards

0
|
3696 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Change the horizontal ordinate if the space changes while using Table?

Posted 5 years ago

Hi, guys I use Table to calculate my problem on a discrete interval as follows:

Clear["`*"];(*????????,??Table*)
b = 2;
y01 = N[Maximize[{-x*a - 6*x*b + 1, -6 <= x <= -(4/8)}, x]];
y11 = N[Maximize[{-x^3*a + 2*x*b - 1, -2 <= x <= 2}, x]];
Y01 = Table[y01, {a, 2, 5, 1}]
Y11 = Table[y11, {a, 2, 5, 1}]
Y = MaximalBy[{Y01, Y11}, First]
Y[[All, All, 1]]
ListPlot[Y[[All, All, 1]], DataRange -> {2, 5}]
Y[[1, All, 2, All, 2]]
ListPlot[Y[[1, All, 2, All, 2]], DataRange -> {2, 5}]

It ( DataRange -> {2, 5}) works with ListPlot[Y[[All, All, 1]], not with ListPlot[Y[[1, All, 2, All, 2]]. More importantly, if I changes space from 1 to 2, that is

Clear["`*"];(*????????,??Table*)
b = 2;
y01 = N[Maximize[{-x*a - 6*x*b + 1, -6 <= x <= -(4/8)}, x]];
y11 = N[Maximize[{-x^3*a + 2*x*b - 1, -2 <= x <= 2}, x]];
Y01 = Table[y01, {a, 2, 5, 2}]
Y11 = Table[y11, {a, 2, 5, 2}]
Y = MaximalBy[{Y01, Y11}, First]
Y[[All, All, 1]]
ListPlot[Y[[All, All, 1]], DataRange -> {2, 5}]
Y[[1, All, 2, All, 2]]
ListPlot[Y[[1, All, 2, All, 2]], DataRange -> {2, 5}]

It does not work for both ListPlot[Y[[All, All, 1]] and ListPlot[Y[[1, All, 2, All, 2]]. Therefore, my problem is how to change the horizontal ordinate if the space changes when I use Table? Thank you very much!

POSTED BY: Shaoyan Robert
2 Replies
Posted 5 years ago

In the first example this fails

ListPlot[Y[[1, All, 2, All, 2]], DataRange -> {2, 5}]

because a list of lists is passed to ListPlot. You should Flatten it first

Y[[1, All, 2, All, 2]]
(* {{-6.}, {-6.}, {-6.}, {-6.}} *)

In the second example, Y[[All, All, 1]] returns {{85., 97.}} which ListPlot interprets as x and y values, so a single point is plotted. Remove the nested list.

ListPlot[Y[[All, All, 1]] // Flatten, DataRange -> {2, 5}]

enter image description here

POSTED BY: Rohit Namjoshi

Your Y[[1, All, 2, All, 2]] is a list of lists. You get a plot with either of the following:

ListPlot[Flatten[Y[[1, All, 2, All, 2]]], DataRange -> {2, 5}]
ListPlot[x /. Y[[1, All, 2, All]], DataRange -> {2, 5}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract