User talk:Vk3dpi: Difference between revisions

From Amateur Radio Wiki
Jump to navigation Jump to search
(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...)
 
(Removing all content from page)
 
Line 1: Line 1:
<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> denotes <i>parallel</i>.
For example, <tt>s(1,2,3,p(2,2))</tt> denotes a series combination of 4 resistors, with the fourth being a parallel combination of two resistors. [Each number is the number of <i>ohms</i> of the resistor.]
<p/>
<!--
<script src="../lib/utilities.js">
</script>
-->


<!-- CALCULATOR BEGINS HERE -->
<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>
<div style="margin-left:30%;margin-right:30%;background-color:blanchedalmond;
border:medium solid darkkhaki;">
<center>
<form>
<b>Series-parallel calculator</b>
<p/>
Input:
<input type="text" size="30" value="s(1,2,3,p(2,2))" name="inFld"
onFocus="clearOutput(this.form);">
<br/>
<input type="button" value="Evaluate"
onClick="evaluateX(this.form)">
Output:
<input type="text" name="outFld" size="8" onFocus="blur();">
</form>
</center>
</div>
<!-- CALCULATOR ENDS HERE -->
<p/>
<i>Examples</i>. Copy-and-paste any of the following examples into the input field and then press <tt>Evaluate</tt>.
<ul type="a">
<li>Three resistors in series: <tt>s(1,2,3)</tt>
<li>Two resistors in parallel: <tt>p(2,2)</tt>
<li>The circuits (a) and (b) in series: <tt>s(1,2,3,p(2,2))</tt>
<li>The circuits (a) and (b) in parallel: <tt>p(s(1,2,3),p(2,2))</tt>
</ul>
<i>Note</i>. 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.
<p/>
<i>Feedback</i>. Send comments to <a href="mailto:bettyw123@optusnet.com.au">VK3DPI</a>.
<p><hr/>
<font size=2>
<script>
  document.write("Document: <i> " + document.title);
  var now = new Date();
  var yr = now.getYear();
  document.write(" &#169; " + yr + " D.R. Watson</i><br>");
  document.write("URL:<i> " + document.URL + "</i><br>");
  document.write("Last update: <i>" + document.lastModified + "</i>");
</script>
</font>
</body>
</html>

Latest revision as of 23:45, 3 April 2009