محاسبه فرمول یک تابع، بر اساس مختصات دو نقطه از آن تابع (با javascript)
این کد، مختصات دو نقطه از تابع را دریافت می کند و سپس فرمول متناظر با تابع را محاسبه می نماید. علاوه بر این، فرمول خط موازی (Parallel) و فرمول خط عمود (Perpendicular) و شیب منحنی (Slope) نیز محاسبه می گردد :
کدها :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function calculate() {
var y = new Array();
y[0] = null;
y[1] = document.calculator.y1.value;
y[2] = document.calculator.y2.value;
var x = new Array();
x[0] = null;
x[1] = document.calculator.x1.value;
x[2] = document.calculator.x2.value;
var m = (y[2] - y[1]) / (x[2] - x[1]);
var b = y[1]-(m * x[1]);
var formula = "y="+m+"x + "+b;
var rand = parseInt(Math.random() * 7);
var parf = "y="+m+"x + "+rand;
var newm = m / -1;
var perf = "y="+newm+"x + "+b;
document.calculator.formula.value = formula;
document.calculator.slope.value = m;
document.calculator.yint.value = b;
document.calculator.parf.value = parf;
document.calculator.perf.value = perf;
}
</script>
</head>
<body>
<form name="calculator">
Enter coordinate values:
<table border=0>
<tr>
<td>X1:</td>
<td><input type=text name=x1 size=10></td>
</tr>
<tr>
<td>Y1:</td>
<td><input type=text name=y1 size=10></td>
</tr>
<tr>
<td>X2:</td>
<td><input type=text name=x2 size=10></td>
</tr>
<tr>
<td>Y2:</td>
<td><input type=text name=y2 size=10>
<input type=button value="Get Results" onClick="calculate();"></td>
</tr>
<tr>
<td>Formula:</td>
<td><input type=text name=formula size=50></td>
</tr>
<tr>
<td>Slope:</td>
<td><input type=text name=slope size=50></td>
</tr>
<tr>
<td>Y-Intercept:</td>
<td><input type=text name=yint size=50></td>
</tr>
<tr>
<td>Parallel Line Formula:</td>
<td><input type=text name=parf size=50></td>
</tr>
<tr>
<td>Perpendicular Line Formula:</td>
<td><input type=text name=perf size=50></td>
</tr>
</table>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function calculate() {
var y = new Array();
y[0] = null;
y[1] = document.calculator.y1.value;
y[2] = document.calculator.y2.value;
var x = new Array();
x[0] = null;
x[1] = document.calculator.x1.value;
x[2] = document.calculator.x2.value;
var m = (y[2] - y[1]) / (x[2] - x[1]);
var b = y[1]-(m * x[1]);
var formula = "y="+m+"x + "+b;
var rand = parseInt(Math.random() * 7);
var parf = "y="+m+"x + "+rand;
var newm = m / -1;
var perf = "y="+newm+"x + "+b;
document.calculator.formula.value = formula;
document.calculator.slope.value = m;
document.calculator.yint.value = b;
document.calculator.parf.value = parf;
document.calculator.perf.value = perf;
}
</script>
</head>
<body>
<form name="calculator">
Enter coordinate values:
<table border=0>
<tr>
<td>X1:</td>
<td><input type=text name=x1 size=10></td>
</tr>
<tr>
<td>Y1:</td>
<td><input type=text name=y1 size=10></td>
</tr>
<tr>
<td>X2:</td>
<td><input type=text name=x2 size=10></td>
</tr>
<tr>
<td>Y2:</td>
<td><input type=text name=y2 size=10>
<input type=button value="Get Results" onClick="calculate();"></td>
</tr>
<tr>
<td>Formula:</td>
<td><input type=text name=formula size=50></td>
</tr>
<tr>
<td>Slope:</td>
<td><input type=text name=slope size=50></td>
</tr>
<tr>
<td>Y-Intercept:</td>
<td><input type=text name=yint size=50></td>
</tr>
<tr>
<td>Parallel Line Formula:</td>
<td><input type=text name=parf size=50></td>
</tr>
<tr>
<td>Perpendicular Line Formula:</td>
<td><input type=text name=perf size=50></td>
</tr>
</table>
</form>
</body>
</html>
دسته بندی
کدهای آماده برای محاسبه گرها
نظرات 0 0 0