User talk:Vk3dpi

From Amateur Radio Wiki
Revision as of 23:43, 3 April 2009 by Vk3dpi (talk | contribs) (New page: <h2>Series-parallel calculator</h2> This calculator allows you to find the resistance of any series-parallel combination of resistors. <tt>s</tt> denotes <i>series</i>, and <tt>p</tt> deno...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Series-parallel calculator

This calculator allows you to find the resistance of any series-parallel combination of resistors. s denotes series, and p denotes parallel. For example, s(1,2,3,p(2,2)) denotes a series combination of 4 resistors, with the fourth being a parallel combination of two resistors. [Each number is the number of ohms of the resistor.]

<script language="JavaScript"> //UTILITY FUNCTIONS function decnNumber(num){ var tmp = Math.pow(10,num)*this.valueOf(); return (Math.round(tmp))/Math.pow(10,num); } Number.prototype.decn = decnNumber; N = 2; //Sets the number of decimal places in the output //STRING FUNCTIONS function Trim(str){ return LTrim(RTrim(str)); } function LTrim(str){ while (str.charAt(0) == " ") str = str.substring(1); return str; } function RTrim(str){ var i=str.length-1; while (str.charAt(i) == " "){ str = str.substring(0,i); i = str.length -1; } return str; } function countChar(ch,str){ var cnt = 0; for (var idx=0; idx<str.length; idx++) if (str.charAt(idx) == ch) cnt += 1; return cnt; } //THE SERIES AND PARALLEL FUNCTIONS function s(x,y){ var numArgs = s.arguments.length; var sum = 0; for (var i = 0; i < numArgs; i++) sum += s.arguments[i]; return sum; } function p(x,y){ var numArgs = p.arguments.length; var sum = 0; for (var i = 0; i < numArgs; i++) sum += 1/p.arguments[i]; return 1/sum; } //INTERFACE FUNCTIONS function checkInput(str){ str = Trim(str); if (countChar("(", str) != countChar(")",str)) { alert("Parentheses not closed"); return false; } if (str.charAt(0)=="s") return true; if (str.charAt(0)=="p") return true; alert("Begin with s or p");return false; } function evaluateX(f){ if (checkInput(f.inFld.value)) f.outFld.value=(eval(f.inFld.value)).decn(N); } function clearOutput(f){ f.outFld.value = ""; } </script>

<form> Series-parallel calculator

Input: <input type="text" size="30" value="s(1,2,3,p(2,2))" name="inFld" onFocus="clearOutput(this.form);">
<input type="button" value="Evaluate" onClick="evaluateX(this.form)"> Output: <input type="text" name="outFld" size="8" onFocus="blur();"> </form>

Examples. Copy-and-paste any of the following examples into the input field and then press Evaluate.

  • Three resistors in series: s(1,2,3)
  • Two resistors in parallel: p(2,2)
  • The circuits (a) and (b) in series: s(1,2,3,p(2,2))
  • The circuits (a) and (b) in parallel: p(s(1,2,3),p(2,2))

Note. At present there is only minor validation of input. Hence ensure that the syntax of the expression which you enter is correct. Check that parentheses are closed and that the comma-separator is where it is needed.

Feedback. Send comments to <a href="mailto:bettyw123@optusnet.com.au">VK3DPI</a>.


<script>

  document.write("Document:  " + document.title);
  var now = new Date();
  var yr = now.getYear();
  document.write(" © " + yr + " D.R. Watson
"); document.write("URL: " + document.URL + "
"); document.write("Last update: " + document.lastModified + "");

</script>

</body> </html>