Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I solve two equations and have two solutions one by each equation. I want to create list of these roots. Could anyone please help me? Appreciate it.

m02R150 = FindRoot[P1 == 0, {E1, 0.07, 0.1}] m01R150 = FindRoot[P1 == 0, {E1, 0.19, 0.2}] {E1 -> 0.0992422} {E1 -> 0.195237}

What I want is to create a list:

Lm0R150 = {0.0992422, 0.195237}

share|improve this question
    
Could you post a minimal working example ? –  b.gatessucks Mar 6 '13 at 14:11
    
Do you want to change the output from, say,{{x->1},{x->2}} to {1,2}? –  Sjoerd C. de Vries Mar 6 '13 at 14:13
    
yes of course Sjoerd –  TMH Mar 6 '13 at 14:30
    
@b.gatessucks I have posted an example. –  TMH Mar 6 '13 at 14:36
add comment

1 Answer

up vote 1 down vote accepted

You mean like this? This is just a list? Are you just asking how to make one list out of 2 or more lists? If so, this question will be closed soon as being too localized. Unless there is more to this question than meets the eyes :)

eq1 = x^3 - 2 x == 0;
eq2 = x^4 + 3 x^2 - 2 == 0;
sol1 = Solve[eq1, x];
sol2 = Solve[eq2, x];
listOfAllRoots = Flatten[x /. {sol1, sol2}]

Mathematica graphics

For many equations:

eq1 = x^3 - 2 x == 0;
eq2 = x^4 + 3 x^2 - 2 == 0;
eq3 = x^4 + 3 x^3 - 2 x == 0;
allSolutions = Solve[#, x] & /@ {eq1, eq2, eq3}
allRoots = Flatten[x /. allSolutions]

or just in one go

alRoots = Flatten[x /. Solve[#, x] & /@ {eq1, eq2, eq3}]

Mathematica graphics

or using FindRoot

alRoots = x /. FindRoot[#, {x, 1}] & /@ {eq1, eq2, eq3}

Mathematica graphics

To select only real roots, one way:

alRealRoots = Select[alRoots, FreeQ[#, _Complex] &]
share|improve this answer
    
Thanks Nasser. Yeah this works fine with my code. I have several eq s , then Can I use any other method(using some iteration method.)? –  TMH Mar 6 '13 at 14:44
    
As you can see, I have to use FindRoot[].Can I use this code with FindRoot instead of Solve[]. And also, can I extract only real solutions. –  TMH Mar 6 '13 at 14:52
    
Thanks a lot Nasser. One more thing,Can I extract only real solutions? –  TMH Mar 6 '13 at 15:01
    
Many Thanks Nasser. In the line one you wrote for FindRoot, alRoots = x /. FindRoot[#, {x, 1}] & /@ {eq1, eq2, eq3} Is this x, one {x,1}. With this line I am getting an error –  TMH Mar 6 '13 at 15:12
    
And also, It works with your code.But, not mine. May be a mistake of my code. But, it doesn't pick all the solutions. Am I right? –  TMH Mar 6 '13 at 15:15
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.