0
|
6364 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
GROUPS:

# Assign from Solve to variable with the same name

Posted 11 years ago
 Hi, I have a problem:I use Solve to get the solutions of equations, but here comes the problem. I seem to be unable to find an easy way to assign all the outputs of Solve to variables with the same name at once.This is how I use SolveInput: sol := Solve[{eq1, eq2, eq3, eq4, eq5, eq6}, {var1, var2, var3, var4, var5, var6}]Output: {var1 -> 14515., var2 -> 1242.27, var3 -> 13272.7, var4 -> 1058.78, var5 -> 12213.9, var6 -> 2281.53}Now I have six outputs and I want to assign them to the variables with the same name. E. g. Solve gives me {var1 -> 14515} and I want to assign to variable called 'var1'. I know it can somehow be done by /.sol[[1]] etc., but I'd like to assign them all at once without having to list every variable and assign it extra.Could you help me, please? Thank you
4 Replies
Sort By:
Posted 11 years ago
 I apologize. I made two mistakes. First I wrote the line claiming it would solve your problem. Second I did not test that before posting. I should be better than that.Please try this correction (* evaluate your code prior to your solve and then this code *) sol = Solve[{r1, r2, r3, r4, r5, r6}, vars][[1]];  MapThread[Set, {vars, vars /. sol}];  (* and then look at the value assigned to your variables *) nF1  (* and *)nD1(* and ... *)I just checked this and I believe I have corrected my mistake.Thank you for checking what I did and reporting my mistake.
Posted 11 years ago
 Thank you again, that works great!
Posted 11 years ago
 Is this acceptablevars = {var1, var2, var3, var4, var5, var6};vars = vars /. Solve[{eq1, eq2, eq3, eq4, eq5, eq6}, vars]
Posted 11 years ago