I want to calculate the derivative and the integral using javascript, but when I try to return the use inputted equation. Nothing displays or a get a non-real answer.
HTML
Equation<br>
<input type="text" name="equation" id="equation" class="form"><br>
Point<br>
<input type="text" name="point" id="point" class="form"><br>
<p id="submit" onclick="submit()" name="solve">click</p><br>
JavaScript
function submit() {
var equation = +document.getElementById("equation").value;
var point = +document.getElementById("point").value;
//console.log(point);
var d = .0001;
var a = (point +a)*a;
var startPoint;
function integral(f) {
for(startPoint= 0; startPoint < point; startPoint+=d){
intAnswer +=(f(startPoint+d)+f(startPoint-d))*(d)*(1/2);
}
return intAnswer;
}
function f(x) {
return equation;
}
function diff(f) {
return function(x) {
return ((f(x+a)-f(x-a))/(2*a));
};
}
}
I want to input x*x
to get X^2
but that does not work. Anyone know why?
You can try to create function from input like this:
var f = new Function('x', 'return ' + equation);
This will evaluate your string.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments