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]]
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?
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
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP