Message Boards Message Boards

0
|
18141 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

Using the Solve function to find Temperature of a system, I receive an output of

T -> x

How can I remove the T -> from the output so I can use the number in a graph (or whatever)?

Example of code:

For[i = 1, i < 18, i++,
 AppendTo[intTemp, 
  Solve[tungParabola == (vcData[[1, i, 1]]/vcData[[1, i, 2]])/w150] [[2]] ] ]
POSTED BY: Jeb Jennings
3 Replies
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
Posted 9 years ago

Excellent! That solved my problem.

Thank you!

POSTED BY: Jeb Jennings
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
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