Solving the equation for a squared variable?

Given an expression (polynomial or any equation in general) such as

as^2+b = 0 

I want to solve for s ^ 2 to get s ^ 2 = -b / a. We all know that you can’t just write

 Solve[eq==0,s^2] 

because s ^ 2 is not a "variable". only s is a "variable". So what i do

 eq = as^2+b; sol = First@Solve [eq==0/.s^2->z,z]; z/.sol -(b/a) 

I was wondering if there is a way to do this without an intermediate replacement? I tried many teams, but did not have time (to reduce, collect, eliminate, multiply, etc.).

thanks --Nasser

+7
source share
2 answers

One way is to solve for s and then put it ...

 eq=as^2+b; sol=#^2 &@ (s/.Solve[eq==0,s])//DeleteDuplicates Out[1]= {-(b/a)} 
+3
source

You can use the Note package , but this leads to other problems. So here is your original equation:

 In[1]:= Solve[b + as^2 == 0, s^2] During evaluation of In[1]:= Solve::ivar: s^2 is not a valid variable. >> Out[1]= Solve[b + as^2 == 0, s^2] 

Now Symbolize s ^ 2, so a normal Mathematica evaluator treats it like any other character

 In[2]:= Needs["Notation`"] In[3]:= Symbolize[ParsedBoxWrapper[SuperscriptBox["s", "2"]]] In[4]:= Solve[b + as^2 == 0, s^2] Out[4]= {{s^2 -> -(b/a)}} 

The problem is that s ^ 2 is really regarded as just another character, for example

 In[6]:= Sqrt[s^2] // PowerExpand Out[6]= Sqrt[s^2] 

A workaround is to replace s ^ 2 with s * s, since Symbolize only affects user-entered expressions (i.e., at the level of interpretation of the entered box structures)

 In[7]:= Sqrt[s^2] /. s^2 -> ss // PowerExpand Out[7]= s 
+2
source

All Articles