Message Boards Message Boards

0
|
18229 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Solve Function: How can I remove x-> from the output?

Posted 9 years ago
POSTED BY: Jeb Jennings
3 Replies
Posted 5 years ago

hello, i am attaching a file. I am getting this solution for my problem. again i want this values as an input to next stage of programming. so i want to replace '==' sign by equal sign. How can i do this ?

Attachments:
POSTED BY: SUSHREE DAS
Posted 9 years ago

Excellent! That solved my problem.

Thank you!

POSTED BY: Jeb Jennings
Posted 9 years ago

Solve is giving you a Rule for T, which is much more polite than setting the variable T to some value. You can use the Rule by a Replace, for which the shortcut is /. (PS. It's a good idea to begin user symbols with lower case, so they don't override Mathematica definitions. )

In[1]:= solution = Solve[3 x + 5 == 2, x]

Out[1]= {{x -> -1}}

In[2]:= solutionForX = x /. solution

Out[2]= {-1}

In[3]:= (* You get the nested list because Solve has the possibility \
of offering multiple solutions. You can de-nest like this *)
solutionForX = x /. solution[[1]]

Out[3]= -1

In[4]:= (* this has set the value for solutionForX *)

In[5]:= solutionForX

Out[5]= -1

In[6]:= (* you could have set a value for x, but that can be annoying \
if you later want to use it without definition, asn in In[1] *)
x = x /. solution[[1]]

Out[6]= -1

In[7]:= x

Out[7]= -1
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract