Anonymous User

# what am i missing to make this work?

Anonymous User
Posted 8 years ago
2835 Views
|
2 Replies
|
0 Total Likes
|
 hi everybody! Need your answer which helps me understand why this don't work? solve = NSolve[{x - y == 1, 2 x + y == 1}, {x, y}]; x = Extract[solve, {1}]; y = Extract[solve, {2}]; x + y
2 Replies
Sort By:
Posted 8 years ago
 Adam--In your code you were extracting the solution to solve, which turns out to be a row vector with dimensions 1,2: solve = NSolve[{x - y == 1, 2 x + y == 1}]; Dimensions[solve] Your extract function was trying to pull the second row of solve, which doesn't exist. I utilize the two bracket position notation instead of the Extract function so I can keep things straight. Second, don't assign a value to a variable that you are trying to keep a variable. Mathematica's Solve function outputs a list of replacement rules and doesn't assign a value to the variables assigned in the Solve function. This way, those variables remain variables and the output of your Solve function won't change in the future, even if you rerun it multiple times.
Posted 8 years ago
 . In[1]:= solve = NSolve[{x - y == 1, 2 x + y == 1}, {x, y}] Out[1]= {{x -> 0.666667, y -> -0.333333}} In[2]:= Extract[solve, {1}] Out[2]= {x -> 0.666667, y -> -0.333333} In[3]:= Extract[solve, {2}] During evaluation of In[3]:= Extract::partw: Part 2 of {{x->0.666667,y->-0.333333}} does not exist. >> Out[3]= Extract[{{x -> 0.666667, y -> -0.333333}}, {2}] In[4]:= x + y /. First[solve] Out[4]= 0.333333