TransWikia.com

Reducing solutions from Solve to positive solutions

Mathematica Asked on February 7, 2021

Consider the following lines;

Clear[r, R, H, s]
rel1 = 2 r == 1/2 H;
rel2 = r/R == (H - r)/s;
rel3 = H^2 + R^2 == s^2;
solH = Solve[rel1, H][[1]]
sols = Solve[rel2 /. solH, s][[1]]
solR = Solve[rel3 /. solH /. sols, R, PositiveReals][[1]]

Quote = ([Pi] R s + [Pi] R^2)/(4 [Pi] r^2) /. sols /. solR [[1]]
  1. For the solR line I added PositiveReals to avoid two solutions where I manually had to use [[2]] to specify the correct solution. However, clearly, and logically, Mathematica does not know if $r>0$. How can I state/define that, perhaps as a ‘preface,’ after Clear, before calculations starts?

  2. Is it necessary to use [[1]] for solH and sols (and for solR)? I got an error when removing them from solH and sols when solR is calculated. Is there a better way to write these two lines without using [[1]]?

Any other comments and recommendations to improve the code are most welcome.

TIA

One Answer

You can simplify the solution and give r > 0 as an assumption:

solR = Simplify[Solve[rel3 /. solH /. sols, R, PositiveReals][[1]], Assumptions -> {r > 0}]

I doubt there is a better way to access the solution than [[1]] as Solve always returns a list, of which you are interested in the first element.

Answered by kloppy on February 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP