Group Abstract Group Abstract

Message Boards Message Boards

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

Assign the results from Solve[] to new variables

Posted 2 years ago

Hello everyone, I write this message to see if somebody can help me with a specific question, please. I need to assign some results from Solve[] to new variables. Here there is an example:

Solve[{ x + y == 5 , x - y == 3 }, {x ,y} ]

Wolfram Mathematica gives me this:

{x  --> 4} , {y --> 1}

Now I need to work with this solution in new variables, like "a" and "b". It means, let "a" takes the x's value (a = 4) and "b" takes the y's value (b = 1). And continue working with a and b... How can I do it?

Thank you very much in advance for your help.
Best regards.
Oscar.

4 Replies
Posted 2 years ago

Please study this carefully. Look up /. in the documentation and understand it.

In[1]:= Solve[{ x + y == 5 , x - y == 3 }, {x ,y} ]
Out[1]= {{x->4,y->1}}

In[2]:= {x,y}/.Solve[{ x + y == 5 , x - y == 3 }, {x ,y} ]
Out[2]= {{4,1}}

In[3]:= {{a,b}}={x,y}/.Solve[{ x + y == 5 , x - y == 3 }, {x ,y} ]
Out[3]= {{4,1}}

In[4]:= a
Out[4]= 4

In[5]:= b
Out[5]= 1

In[6]:= 2*a-3*b
Out[6]= 5
POSTED BY: Bill Nelson

Hello Mariusz, I have tried with your suggestion and it works! Thank you so much. I can continue working with my solutions.

I wish you a nice day. Best regards.

Hello Bill, thank you very much for your help. I have used it and it works well!

Have a nice day. Best regards.

$Version
(*"13.2.0 for Microsoft Windows (64-bit) (November 18, 2022)"*)

{a, b} = SolveValues[{x + y == 5, x - y == 3}, {x, y}][[1]]
{a, b}
(*{4, 1}*)
POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard