Group Abstract Group Abstract

Message Boards Message Boards

0
|
2K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Implementing L'Hospital Rule?

Posted 2 years ago

I've been trying to implement the function for applying the L'Hospital Rule after the test conditions have been satisfied. One would think just this would be enough to cut the mustard:

lhospital = D[Numerator[#], #2]/ D[Denominator[#], #2] &

But, there seems to be simplification & substitution going on in the engine for this to work. I've posted the answer to some other site, & somebody came up with another snippet:

lhospital = 
  Function[{f, x}, 
   Divide @@ D[NumeratorDenominator[Unevaluated[f]], x], HoldFirst];

Though some cases still seep through (say, trigonometric ones). He then added this command for the engine:

SetSystemOptions["SimplificationOptions" -> {"AutosimplifyTrigs" -> False}];

So now it works for the majority of examples I posed, yet the function has stopped working to what `lhospital = D[Numerator[#], #2]/ D[Denominator[#], #2] & used to work in. Particularly these bunch of fractional terms I am trying to tame:

-((ao^3 (r2 r3 rb rc + 
        r1 (r4 ra rc + r3 rb rc + 
           r3 ra (rb + rc))) rgsink vref + (r1 + r2) (r3 + 
        r4) (ra rc rgsink + rb rc rgsink + ra rb (rc + rgsink)) vth + 
     ao (r2 (r4 ra rb rgsink vref + r3 rb rc rgsink vth + 
           r3 ra (rb rc vth + rc rgsink vth + 
              rb rgsink (vref + vth))) + 
        r1 (2 r3 rb rc rgsink vth + r4 rb rc rgsink vth + 
           r4 ra (rb rc vth + rc rgsink vth + 
              rb rgsink (vref + vth)) + 
           r3 ra (2 rb rc vth + 2 rc rgsink vth + 
              rb rgsink (vref + 2 vth)))) + 
     ao^2 (r2 (r3 rb rc + r4 (ra + rb) rc + 
           r3 ra (rb + rc)) rgsink vref + 
        r1 (r4 (rb rc + ra (rb + rc)) rgsink vref + 
           r3 (ra rc rgsink (vref + vth) + rb rc rgsink (vref + vth) +
               ra rb (rc vth + 
                 rgsink (2 vref + vth))))))/(r2 r4 (-((-1 + 
             ao^2) ra rc rgsink) - (-1 + ao^2) rb rc rgsink + 
        ra rb (rc + rgsink - ao rgsink)) + 
     r2 r3 ((1 + ao - ao^2) ra rc rgsink - (-1 + ao) (1 + 
           ao)^2 rb rc rgsink + (1 + ao) ra rb (rc + rgsink - 
           ao rgsink)) + (1 + 
        ao) r1 r3 ((1 + ao - ao^2) ra rc rgsink + (1 + ao - 
           ao^2) rb rc rgsink + (1 + ao) ra rb (rc + rgsink - 
           ao rgsink)) + 
     r1 r4 ((1 + ao - ao^2) rb rc rgsink + (1 + 
           ao) ra (-((-1 + ao^2) rc rgsink) + 
           rb (rc + rgsink - ao rgsink)))))
POSTED BY: Tempus Nomen
2 Replies
Posted 2 years ago

Its to handle expressions such as this, in respect to variable ao:

solu7 = -((ao^3 (r2 r3 rb rc + 
r1 (r4 ra rc + r3 rb rc + 
r3 ra (rb + rc))) rgsink vref + (r1 + r2) (r3 + 
r4) (ra rc rgsink + rb rc rgsink + ra rb (rc + rgsink)) vth + 
ao (r2 (r4 ra rb rgsink vref + r3 rb rc rgsink vth + 
r3 ra (rb rc vth + rc rgsink vth + 
rb rgsink (vref + vth))) + 
r1 (2 r3 rb rc rgsink vth + r4 rb rc rgsink vth + 
r4 ra (rb rc vth + rc rgsink vth + 
rb rgsink (vref + vth)) + 
r3 ra (2 rb rc vth + 2 rc rgsink vth + 
rb rgsink (vref + 2 vth)))) + 
ao^2 (r2 (r3 rb rc + r4 (ra + rb) rc + 
r3 ra (rb + rc)) rgsink vref + 
r1 (r4 (rb rc + ra (rb + rc)) rgsink vref + 
r3 (ra rc rgsink (vref + vth) + rb rc rgsink (vref + vth) +
ra rb (rc vth + 
rgsink (2 vref + vth))))))/(r2 r4 (-((-1 + 
ao^2) ra rc rgsink) - (-1 + ao^2) rb rc rgsink + 
ra rb (rc + rgsink - ao rgsink)) + 
r2 r3 ((1 + ao - ao^2) ra rc rgsink - (-1 + ao) (1 + 
ao)^2 rb rc rgsink + (1 + ao) ra rb (rc + rgsink - 
ao rgsink)) + (1 + 
ao) r1 r3 ((1 + ao - ao^2) ra rc rgsink + (1 + ao - 
ao^2) rb rc rgsink + (1 + ao) ra rb (rc + rgsink - 
ao rgsink)) + 
r1 r4 ((1 + ao - ao^2) rb rc rgsink + (1 + 
ao) ra (-((-1 + ao^2) rc rgsink) + 
rb (rc + rgsink - ao rgsink)))))

The funny thing is with the function definition I'm working with:

lhospital = 
Function[{f, x}, 
Switch[Head[Unevaluated[f]], Times, 
Divide @@ D[NumeratorDenominator[Unevaluated[f]], x]], HoldAll]

(I used Switch, so I can keep adding more cases as more heads needs to be handled or extended to)

This works:

lhospital[-((ao^3 (r2 r3 rb rc + 
r1 (r4 ra rc + r3 rb rc + 
r3 ra (rb + rc))) rgsink vref + (r1 + r2) (r3 + 
r4) (ra rc rgsink + rb rc rgsink + ra rb (rc + rgsink)) vth + 
ao (r2 (r4 ra rb rgsink vref + r3 rb rc rgsink vth + 
r3 ra (rb rc vth + rc rgsink vth + 
rb rgsink (vref + vth))) + 
r1 (2 r3 rb rc rgsink vth + r4 rb rc rgsink vth + 
r4 ra (rb rc vth + rc rgsink vth + 
rb rgsink (vref + vth)) + 
r3 ra (2 rb rc vth + 2 rc rgsink vth + 
rb rgsink (vref + 2 vth)))) + 
ao^2 (r2 (r3 rb rc + r4 (ra + rb) rc + 
r3 ra (rb + rc)) rgsink vref + 
r1 (r4 (rb rc + ra (rb + rc)) rgsink vref + 
r3 (ra rc rgsink (vref + vth) + rb rc rgsink (vref + vth) +
ra rb (rc vth + 
rgsink (2 vref + vth))))))/(r2 r4 (-((-1 + 
ao^2) ra rc rgsink) - (-1 + ao^2) rb rc rgsink + 
ra rb (rc + rgsink - ao rgsink)) + 
r2 r3 ((1 + ao - ao^2) ra rc rgsink - (-1 + ao) (1 + 
ao)^2 rb rc rgsink + (1 + ao) ra rb (rc + rgsink - 
ao rgsink)) + (1 + 
ao) r1 r3 ((1 + ao - ao^2) ra rc rgsink + (1 + ao - 
ao^2) rb rc rgsink + (1 + ao) ra rb (rc + rgsink - 
ao rgsink)) + 
r1 r4 ((1 + ao - ao^2) rb rc rgsink + (1 + 
ao) ra (-((-1 + ao^2) rc rgsink) + 
rb (rc + rgsink - ao rgsink))))), ao]

But this doesn't:

lhospital[solu7, ao]

Power::infy: Infinite expression 1/0 encountered.
ComplexInfinity

When numerator & denominator both still have ao as polynomials (therefore going to infinity).

POSTED BY: Tempus Nomen

What code did you apply to this expression? In particular, what is the second argument (the variable of interest)?

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard