Message Boards Message Boards

5 Replies
2 Total Likes
View groups...
Share this post:

How do you substitute multiple equations into one expression?

Hi All,
I am very new at using Matematica and was hoping one of you could help me. I have 4 equations and I am trying to get Matematica to substitue them into the 5th equation. 
Gs == HVs/HHs

Gb == HVb/HHb
Ps == (VVs - VHs*Gs)/(VVs + VHs*Gs)
Pb == (VVb - VHb*Gb)/(VVb + VHb*Gb)

Pc == (Ps^3 - Pb)
I just want the software to combine them for me and give me the expression for Pc in terms of VV, VH, HV and HH.  This was a quick test before I start putting more complex expression together but i cant even get this to work it seems. I tried using replate, solve and some other commands but It doesnt seem to do it or I am not using the right syntax.  Any ideas as to how to do this or where i might be going wrong? I would apreciate any and all help.
POSTED BY: Veselin Dobrev
5 Replies
Posted 11 years ago
Solve can do this work for you. Give it the equations, tell it to solve for Pc, while eliminating what you don't want:
eqs = {Gs == HVs/HHs,
   Gb == HVb/HHb,
   Ps == (VVs - VHs*Gs)/(VVs + VHs*Gs),
   Pb == (VVb - VHb*Gb)/(VVb + VHb*Gb),
   Pc == (Ps^3 - Pb)};
Solve[eqs, Pc, {Gs, Pb, Ps, Gb}][[1, 1]] // FullSimplify
Pc -> (2 HHs HVb VHb VVs (3 HVs^2 VHs^2 + HHs^2 VVs^2) -
  2 HHb HVs VHs VVb (HVs^2 VHs^2 + 3 HHs^2 VVs^2))/((HVb VHb +
    HHb VVb) (HVs VHs + HHs VVs)^3)
POSTED BY: David Keith
Posted 11 years ago
I am unsure what difficulty you are having. I try to test the code before I post it. I just scraped each version, pasted them into a notebook, evaluated them and compared the results. Both methods produce the same result for me. Perhaps try each with a fresh start of an empty notebook.

For display purposes only, you might try
and see if this shows something closer to what you would like to read, but you often cannot then use the result of something displayed in TraditionalForm as the input for a further calculation, so keep a copy of that in a variable and only use a copy for display purposes.
POSTED BY: Bill Simpson
Thank you so much. I was able to use the second option Pc=(Ps^3-Pb)//. ....  but not the first. What am i doing wrong or is there a setting i need to change in order to be able to use both inputs? Also is there wasy to Make mathematica display addition first then subtraction aka  (VVb-(HVb*VHb)/HHb)) ?
POSTED BY: Veselin Dobrev
Posted 11 years ago
In[1]:= Gs = HVs/HHs;
Gb = HVb/HHb;
Ps = (VVs - VHs*Gs)/(VVs + VHs*Gs);
Pb = (VVb - VHb*Gb)/(VVb + VHb*Gb);
Pc = (Ps^3 - Pb)

Out[5]= -((-((HVb*VHb)/HHb) + VVb)/((HVb*VHb)/HHb + VVb)) + (-((HVs*VHs)/HHs) + VVs)^3/((HVs*VHs)/HHs + VVs)^3
In[1]:= Pc=(Ps^3-Pb)//.{Gs->HVs/HHs, Gb->HVb/HHb, Ps->(VVs-VHs*Gs)/(VVs+VHs*Gs), Pb->(VVb-VHb*Gb)/(VVb+VHb*Gb)}

Out[1]= -((-((HVb*VHb)/HHb) + VVb)/((HVb*VHb)/HHb + VVb)) + (-((HVs*VHs)/HHs) + VVs)^3/((HVs*VHs)/HHs + VVs)^3
POSTED BY: Bill Simpson
How do you substitute multiple equations into one expression?
POSTED BY: Veselin Dobrev
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract