# Generate a table from Solve or NSolve and plot it?

**URL:** <https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657>\
**Category:** Questions\
**Tags:** equation-solving\
**Created:** [February 10, 2019, 5:55pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657 "2019-02-10T17:55:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hongychiu](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hongychiu](https://community.wolfram.com/u/hongychiu)\
**Post date:** [February 10, 2019, 5:55pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/1 "2019-02-10T17:55:58Z")

</div>

I have a simple question. I want to generate a list. To make things simple, I use a simple model.

```
xt = Table[{NSolve[x^2 - .001 i == 0 && x > 0]}, {i, 8}];

```

This generates a table, but when I inquire the value of xt, I got an answer like

```
xt[[4]]

```

Answer is

```
{{{x -> 0.0632456}}}

```

How can I ListPlot xt?  
If I want to ListPlot xt versus another table, how can I do it?  
Much thanks to anyone who can tell me.

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [February 10, 2019, 8:06pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/2 "2019-02-10T20:06:40Z")

</div>

A very simple way would be:

```
xt = Table[{i, NSolve[x^2 - .001 i == 0 && x > 0]}, {i, 8}];
xt1 = xt /. {{Rule[a_, b_]}} :> b;
ListPlot[xt1]

```

---

<div class="post-metadata">

**Author:** ![hongychiu](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hongychiu](https://community.wolfram.com/u/hongychiu)\
**Post date:** [February 11, 2019, 4:44pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/3 "2019-02-11T16:44:39Z")

</div>

Thanks, it works. Can you spare a few moments to explain what you are doing? It will be a great education to me.

---

<div class="post-metadata">

**Author:** ![anon21378091](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@anon21378091](https://community.wolfram.com/u/anon21378091)\
**Post date:** [February 11, 2019, 7:26pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/4 "2019-02-11T19:26:42Z")

</div>

Thank you. I got the following answers.

```
In[16]:= xt = Table[{NSolve[x^2 - .001 i == 0 && x > 0]}, {i, 8}];

In[21]:= {
 {xt1 = xt /. {{Rule[a_, b_]}} :> b;},
 {\[Placeholder]}
}

Out[21]= {{Null}, {\[Placeholder]}}

In[23]:= xt1

Out[23]= {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456}, \
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}

```

Now, how can I get rid of the parenthesis so that the answer will look like

```
 {0.0316228, 0.0447214, 0.0547723, 0.0632456, \
0.0707107, 0.0774597, 0.083666, 0.0894427}
so that I can list plot xt1 with another table, like
yt1=(1, 2, 3, 4, 5, 6, 7, 8}

```

?

Much thanks for your time.

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [February 11, 2019, 10:50pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/5 "2019-02-11T22:50:04Z")

</div>

`xt` is a list of elements containing two components: the x-value of the intended plot and - in some nested form - the y-value (the result of `NSolve`). I extracted this value simply using a replacement rule, which could as well be written like so:

```
xt1 = xt /. {{a_ -> b_}} :> b

```

which is probably more similar to what you are seeing in `xt`.

General hint: Use `FullForm` in combination with the excellent documentation, e.g.:

```
{{a_ -> b_}} :> b // FullForm

```

---

<div class="post-metadata">

**Author:** ![ivarjohannesen](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ivarjohannesen](https://community.wolfram.com/u/ivarjohannesen)\
**Post date:** [February 14, 2019, 10:45am UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/6 "2019-02-14T10:45:48Z")

</div>

Table[xt[[n,2]],{n,8}]

---

<div class="post-metadata">

**Author:** ![ivarjohannesen](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ivarjohannesen](https://community.wolfram.com/u/ivarjohannesen)\
**Post date:** [February 14, 2019, 10:51am UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/7 "2019-02-14T10:51:41Z")

</div>

Sorry, I ment Table[xt1[[n,2]],{n,8}]

---

<div class="post-metadata">

**Author:** ![hongychiu](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hongychiu](https://community.wolfram.com/u/hongychiu)\
**Post date:** [February 14, 2019, 8:44pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/8 "2019-02-14T20:44:46Z")

</div>

I followed your suggestion,here is what I got:  
In[24]:= (_Exercise in table manipulation_)  
xt = Table[{NSolve[x^2 - .001 i == 0 && x \> 0]}, {i, 8}];

In[25]:= {  
{xt1 = xt /. {{Rule[a\_, b\_]}} :\> b;},  
{[Placeholder]}  
}

Out[25]= {{Null}, {[Placeholder]}}  
In[26]:= xt1

Out[26]= {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}

In[27]:= Table[xt1[[n, 2]], {n, 8}]

During evaluation of In[27]:= Part::partw: Part 2 of {0.0316228} does not exist.

During evaluation of In[27]:= Part::partw: Part 2 of {0.0447214} does not exist.

During evaluation of In[27]:= Part::partw: Part 2 of {0.0547723} does not exist.

During evaluation of In[27]:= General::stop: Further output of Part::partw will be suppressed during this calculation.

Out[27]= {{{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[1,  
2]], {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[2,  
2]], {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[3,  
2]], {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[4,  
2]], {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[5,  
2]], {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[6,  
2]], {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[7,  
2]], {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}[[8, 2]]}  
I cannot get the anticipated table form like following:  
{0.0316228, 0.0447214, 0.0547723, 0.0632456, 0.0707107,   
0.0774597, 0.083666, 0.0894427}  
Anything wrong? Thanks

---

<div class="post-metadata">

**Author:** ![hongychiu](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@hongychiu](https://community.wolfram.com/u/hongychiu)\
**Post date:** [February 14, 2019, 9:10pm UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/9 "2019-02-14T21:10:51Z")

</div>

I think I have found the solution.  
The following three operations  
In[24]:= (_Exercise in table manipulation_)  
xt = Table[{NSolve[x^2 - .001 i == 0 && x \> 0]}, {i, 8}];

In[25]:= {  
{xt1 = xt /. {{Rule[a\_, b\_]}} :\> b;},  
{[Placeholder]}  
}

Out[25]= {{Null}, {[Placeholder]}}

In[26]:= xt1

Out[26]= {{0.0316228}, {0.0447214}, {0.0547723}, {0.0632456},   
{0.0707107}, {0.0774597}, {0.083666}, {0.0894427}}

generates a 8 d vector, and by using Transpose,  
In[33]:=  
xxt = Transpose[xt1]

Out[33]= {{0.0316228, 0.0447214, 0.0547723, 0.0632456, 0.0707107,  
0.0774597, 0.083666, 0.0894427}}  
Taking the first element,  
In[34]:= xxt[[1]]

Out[34]= {0.0316228, 0.0447214, 0.0547723, 0.0632456, 0.0707107,   
0.0774597, 0.083666, 0.0894427}  
this is the result I wanted.  
Thanks to you, because you,  
ivar johannesen, oslomet, inspired me to look for transpose. This is the greatness of forum discussions, generate inspirations. Hong-Yee Chiu

---

<div class="post-metadata">

**Author:** ![parsonwarren](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@parsonwarren](https://community.wolfram.com/u/parsonwarren)\
**Post date:** [February 21, 2019, 8:50am UTC](https://community.wolfram.com/t/generate-a-table-from-solve-or-nsolve-and-plot-it/13657/10 "2019-02-21T08:50:16Z")

</div>

Helpful information shared thank you for helping out others.
