# How do I use a while-loop to find the gain of a transfer function's limit?

At the moment I can find the limit of my transfer function as follows:

(5 4001.6)/(5 4001.6 + (4 + s) (200 + s)) /. s -> 0


This works as I would expect and provides a final value of 0.961553 In this example my value of gain, k, is 4001.6 so re-writing the expression for arbitrary k would give:

   (5 k)/(5k + (4 + s) (200 + s)) /. s -> 0


I want to find a value of k that makes the result 0.95. To do this I was thinking about using a while loop.

I thought the while loop could start with k=1, compute the limit, test to see if less than 0.95, and if not increment k by one, and perform the test again, until the correct value of k is found:

This is what I have tried:

    k = 1; While[(5 k)/(5 k + (4 + s) (200 + s)) /. s < 0.95, k++]


However I get the error: "ReplaceAll::reps: {s<=0.95} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>"

Any help would be most appreciated.

-
Shouldn't it be (... /. s -> 0) < 0.95? The error message is telling you that you forgot a ->. – Michael E2 Aug 14 '13 at 20:18
Ah, I think Michael has a better handle on your particular intent. Nevertheless consider reading: (1835) for some examples. – Mr.Wizard Aug 14 '13 at 20:19
By the way: FindRoot[0.95 == (5 k)/(5 k + (4 + s) (200 + s)) /. s -> 0, {k, 4000}] Out: {k -> 3040.} – Mr.Wizard Aug 14 '13 at 20:34
FWIW, ControlStaticGains[TransferFunctionModel[(5 k)/(5 k + (4 + s) (200 + s)), s]] will compute the steady-state gains. – Suba Thomas Aug 14 '13 at 21:52
There are easier ways to do this, but I am now confused about your TransferFunction. This can't be an actual transfer function. closed loop basic TF is $\frac{k H(s)}{1+ k H(s)}$ and what you do next is use RootLocusPlot to see where it crosses the $s$ axis for specific $k$. It is easy now to make a manipulate which varies $k$ and see which values causes it to become unstable. – Nasser Aug 14 '13 at 23:11

Rather than try to code the numerical solver loop yourself, Mathematica has great built in functions. In the comments, @Mr.Wizard suggested FindRoot, but Solve may be easier for you:
Solve[((5 k)/(5 k + (4 + s) (200 + s)) /. s -> 0) == .95, k]