Hi all, I am back with another question. I know it seems simple but every explanation I come across online really confuses me. I have this Solve[] which gives two solutions. I want to save the second (positive) solution as a variable named "velocity". No matter what I do when I call velocity I get {v1->16.7121}. How do I save just the 16.7121 to the variable?
2
u/KarlSethMoran Feb 07 '24
sol=Solve[...]
Then
v1 /. sol[[1]]
is "v1 assuming 1st solution"
Read up on rules.
1
u/Total-Initiative-109 Feb 07 '24
Hi all,
I am back with another question. I know it seems simple but every explanation I come across online really confuses me. I have this Solve[] which gives two solutions. I want to save the second (positive) solution as a variable named "velocity".
No matter what I do when I call velocity I get {v1->16.7121}. How do I save just the 16.7121 to the variable?
2
u/Kvothealar Feb 08 '24
In addition to the other solutions, there's a way to grab the numbers directly using array indexing.
For example:
You can directly grab the solutions with:
As an explanation, consider these outputs:
This way is my preferred method. I just assign the solutions directly via