Re: How to remove curly brackets and arrow symbols from a list.

• To: mathgroup at smc.vnet.net
• Subject: [mg58223] Re: How to remove curly brackets and arrow symbols from a list.
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Thu, 23 Jun 2005 05:34:03 -0400 (EDT)
• Organization: The Open University, Milton Keynes, England
• References: <d9av83\$10a\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```T. K. Ghosh wrote:
> Hi Math Guru,
>
> I will be very happy if you could help me to solve the following problem.
> The simplified version of my problem is the following.
> I have a quadratic equation with a parameter, say "p".
>
> Define the function:
> f[x_] := A*X^2 + B*X*p + D  with A, B and D are given.
> "p" is a parameter.
> I solve this equation for a given p:
> w = Solve[f[x]] == 0, X].
> Now I want to make a Table for the solutions of this
> quadratic equation for different values of "p".
> So I write,
> Table[{p,sol},{p,0,10,1}.
> I will get a table which will look like,
> 0   {w -> a}    {w -> -a}
> 1    {w -> b}    {w -> -b}
> 2    {w -> c}    {w -> -c}
> and so on.........
>
> How can I remove the curly brackets and the arrow symbol
> from the TableForm? I would like to plot the 1st column
> vs. 2nd or 3rd column. I must remove those brackets.
> and I wish to get the following form:
> 0  a  -a
> 1  b  -b
> 2  c  -c
>
>
> Hope this can be done easily which I am not aware.
> Any suggestion/solution to this problem is most welcome.
> TKG.
>
Hi,

I am not sure that I have fully understood what you wanted; however, I

First we define the function f and solve the equation for the variable X

In[1]:=
f[x_] := A*X^2 + B*X*p + D

In[2]:=
w = Solve[f[x] == 0, X]

Out[2]=
{{X -> ((-B)*p - Sqrt[-4*A*D + B^2*p^2])/(2*A)},
{X -> ((-B)*p + Sqrt[-4*A*D + B^2*p^2])/(2*A)}}

Since we have not defined any values for A, B and D yet, we get symbolic
solutions that we use in the next line to compute the table.

In[3]:=
sol = Table[w, {p, 0, 10}]

Out[3]=
{{{X -> -(Sqrt[(-A)*D]/A)}, {X -> Sqrt[(-A)*D]/A}},
{{X -> (-B - Sqrt[B^2 - 4*A*D])/(2*A)},
{X -> (-B + Sqrt[B^2 - 4*A*D])/(2*A)}},
{{X -> (-2*B - Sqrt[4*B^2 - 4*A*D])/(2*A)},
{X -> (-2*B + Sqrt[4*B^2 - 4*A*D])/(2*A)}},
{{X -> (-3*B - Sqrt[9*B^2 - 4*A*D])/(2*A)},
{X -> (-3*B + Sqrt[9*B^2 - 4*A*D])/(2*A)}},
{{X -> (-4*B - Sqrt[16*B^2 - 4*A*D])/(2*A)},
{X -> (-4*B + Sqrt[16*B^2 - 4*A*D])/(2*A)}},
{{X -> (-5*B - Sqrt[25*B^2 - 4*A*D])/(2*A)},
{X -> (-5*B + Sqrt[25*B^2 - 4*A*D])/(2*A)}},
{{X -> (-6*B - Sqrt[36*B^2 - 4*A*D])/(2*A)},
{X -> (-6*B + Sqrt[36*B^2 - 4*A*D])/(2*A)}},
{{X -> (-7*B - Sqrt[49*B^2 - 4*A*D])/(2*A)},
{X -> (-7*B + Sqrt[49*B^2 - 4*A*D])/(2*A)}},
{{X -> (-8*B - Sqrt[64*B^2 - 4*A*D])/(2*A)},
{X -> (-8*B + Sqrt[64*B^2 - 4*A*D])/(2*A)}},
{{X -> (-9*B - Sqrt[81*B^2 - 4*A*D])/(2*A)},
{X -> (-9*B + Sqrt[81*B^2 - 4*A*D])/(2*A)}},
{{X -> (-10*B - Sqrt[100*B^2 - 4*A*D])/(2*A)},
{X -> (-10*B + Sqrt[100*B^2 - 4*A*D])/(2*A)}}}

Say that the values of A, B and D are 2, 3 and 5, respectively.

In[4]:=
sol = sol /. {A -> 2, B -> 3, D -> 5}

Out[4]=
{{{X -> (-I)*Sqrt[5/2]}, {X -> I*Sqrt[5/2]}},
{{X -> (1/4)*(-3 - I*Sqrt[31])},
{X -> (1/4)*(-3 + I*Sqrt[31])}},
{{X -> -(3/2) - I/2}, {X -> -(3/2) + I/2}},
{{X -> (1/4)*(-9 - Sqrt[41])},
{X -> (1/4)*(-9 + Sqrt[41])}},
{{X -> (1/4)*(-12 - 2*Sqrt[26])},
{X -> (1/4)*(-12 + 2*Sqrt[26])}},
{{X -> (1/4)*(-15 - Sqrt[185])},
{X -> (1/4)*(-15 + Sqrt[185])}},
{{X -> (1/4)*(-18 - 2*Sqrt[71])},
{X -> (1/4)*(-18 + 2*Sqrt[71])}},
{{X -> (1/4)*(-21 - Sqrt[401])},
{X -> (1/4)*(-21 + Sqrt[401])}},
{{X -> (1/4)*(-24 - 2*Sqrt[134])},
{X -> (1/4)*(-24 + 2*Sqrt[134])}},
{{X -> (1/4)*(-27 - Sqrt[689])},
{X -> (1/4)*(-27 + Sqrt[689])}},
{{X -> (1/4)*(-30 - 2*Sqrt[215])},
{X -> (1/4)*(-30 + 2*Sqrt[215])}}}

Now we have numerical solutions expressed as _replacement rules_. To get
an array of numbers only, we use these rules to replace X by its values
in sol.

In[5]:=
sol = X /. sol

Out[5]=
{{(-I)*Sqrt[5/2], I*Sqrt[5/2]},
{(1/4)*(-3 - I*Sqrt[31]), (1/4)*(-3 + I*Sqrt[31])},
{-(3/2) - I/2, -(3/2) + I/2},
{(1/4)*(-9 - Sqrt[41]), (1/4)*(-9 + Sqrt[41])},
{(1/4)*(-12 - 2*Sqrt[26]),
(1/4)*(-12 + 2*Sqrt[26])},
{(1/4)*(-15 - Sqrt[185]), (1/4)*(-15 + Sqrt[185])},
{(1/4)*(-18 - 2*Sqrt[71]),
(1/4)*(-18 + 2*Sqrt[71])},
{(1/4)*(-21 - Sqrt[401]), (1/4)*(-21 + Sqrt[401])},
{(1/4)*(-24 - 2*Sqrt[134]),
(1/4)*(-24 + 2*Sqrt[134])},
{(1/4)*(-27 - Sqrt[689]), (1/4)*(-27 + Sqrt[689])},
{(1/4)*(-30 - 2*Sqrt[215]),
(1/4)*(-30 + 2*Sqrt[215])}}

Then we transpose the matrix sol to plot easily one or the other column.

In[6]:=
sol = Transpose[sol]

Out[6]=
{{(-I)*Sqrt[5/2], (1/4)*(-3 - I*Sqrt[31]),
-(3/2) - I/2, (1/4)*(-9 - Sqrt[41]),
(1/4)*(-12 - 2*Sqrt[26]), (1/4)*(-15 - Sqrt[185]),
(1/4)*(-18 - 2*Sqrt[71]), (1/4)*(-21 - Sqrt[401]),
(1/4)*(-24 - 2*Sqrt[134]), (1/4)*(-27 - Sqrt[689]),
(1/4)*(-30 - 2*Sqrt[215])}, {I*Sqrt[5/2],
(1/4)*(-3 + I*Sqrt[31]), -(3/2) + I/2,
(1/4)*(-9 + Sqrt[41]), (1/4)*(-12 + 2*Sqrt[26]),
(1/4)*(-15 + Sqrt[185]), (1/4)*(-18 + 2*Sqrt[71]),
(1/4)*(-21 + Sqrt[401]), (1/4)*(-24 + 2*Sqrt[134]),
(1/4)*(-27 + Sqrt[689]), (1/4)*(-30 + 2*Sqrt[215])}}

Line 7 plots the first column with an index for the x-axes starting from
1 (so ranging from 1 to 11 in our case). Line 8 plots the same thing but
with a range from 0 to 10 on the x-axes.

In[7]:=
ListPlot[sol[[1]]];

In[8]:=
ListPlot[Transpose[{Range[0, 10], sol[[1]]}]];

Finally, we construct a nice table with 3 columns.

In[9]:=
TableForm[Transpose[{Range[0, 10], sol[[1]],
sol[[2]]}]]

Out[9]//TableForm=
TableForm[{{0, (-I)*Sqrt[5/2], I*Sqrt[5/2]},
{1, (1/4)*(-3 - I*Sqrt[31]),
(1/4)*(-3 + I*Sqrt[31])}, {2, -(3/2) - I/2,
-(3/2) + I/2}, {3, (1/4)*(-9 - Sqrt[41]),
(1/4)*(-9 + Sqrt[41])},
{4, (1/4)*(-12 - 2*Sqrt[26]),
(1/4)*(-12 + 2*Sqrt[26])},
{5, (1/4)*(-15 - Sqrt[185]),
(1/4)*(-15 + Sqrt[185])},
{6, (1/4)*(-18 - 2*Sqrt[71]),
(1/4)*(-18 + 2*Sqrt[71])},
{7, (1/4)*(-21 - Sqrt[401]),
(1/4)*(-21 + Sqrt[401])},
{8, (1/4)*(-24 - 2*Sqrt[134]),
(1/4)*(-24 + 2*Sqrt[134])},
{9, (1/4)*(-27 - Sqrt[689]),
(1/4)*(-27 + Sqrt[689])},
{10, (1/4)*(-30 - 2*Sqrt[215]),
(1/4)*(-30 + 2*Sqrt[215])}}]

Best regards,
/J.M.

```

• Prev by Date: Re: How to remove curly brackets and arrow symbols from a list.
• Next by Date: free packages
• Previous by thread: Re: How to remove curly brackets and arrow symbols from a list.
• Next by thread: thanks on runs test