Message Boards Message Boards

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

[?] Select specific values from Solve function?

Hello guys! I want to solve a 4th order equation, and to find its solutions. This procedure is straightforward but, after this, I want to select only the last 2 roots, and to store them as variables, say w1 and w2.

sol1 = Solve[equ[t, x, j1] == 0, {t}, Reals];
{{t -> -0.241908}, {t -> -0.173627}, {t -> 0.173627}, {t -> 0.241908}}

If I write

w1 = sol1[[3]];
w2 = sol1[[4]];
Print[w1, w2]

I get this thing

{t->0.173627}{t->0.241908}

But I want only the numerical values, without those useless arrows and letters. HOW CAN I FIX THIS?

Thank you in advance!

POSTED BY: Robert Poenaru
4 Replies

A possible approach:

sol1 = Values@Solve[t^4 + t^3 - 2 t^2 - t + 1 == 0, {t}, Reals];

w1 = sol1[[3, 1]];
w2 = sol1[[4, 1]];
Print["w1 =", w1, ",   w2 =", w2]

w1 =1/2 (-1-Sqrt[5]),   w2 =1/2 (-1+Sqrt[5])

Va multumesc mult pentru solutie. Functioneaza :)

Toate cele bune!

POSTED BY: Robert Poenaru

Cu pl?cere!

Sure, there are other approaches, too. E.g.:

sol1 = Flatten@Solve[t^4 + t^3 - 2 t^2 - t + 1 == 0, {t}, Reals];

w1 = sol1[[3, 2]]
w2 = sol1[[4, 2]]

or

w1 = t /. sol1[[3]]
w2 = t /. sol1[[4]]
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