Cannot return equation from function

Cup of Java

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?

jcubic

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot return equation from function

From Dev

How to create a function to return an equation

From Dev

Cannot return from outside a function or method

From Dev

C++ - Cannot return vector from function

From Dev

Why cannot I return void from a void function

From Dev

Cannot return string from function Kotlin/Android Studio

From Dev

Return an object from a function

From Dev

Return a closure from a function

From Dev

Return from void function

From Dev

Return Traits from function

From Dev

Return a struct from function

From Dev

Return a stream from a function

From Dev

Return an object from a function

From Dev

Return an array from a function

From Dev

Return from different function

From Dev

Return array from a function

From Dev

Vector return from a function

From Dev

Return ComboBox From Function?

From Dev

Return Variable From Function

From Dev

return to function from another function

From Dev

Cannot return HTML from a Controller

From Dev

Cannot return from async method

From Dev

Node js function requires a return value but value comes from callback so cannot be returned

From Dev

C linkage function cannot return C++ class - error resulting from the contents of my method

From Dev

Node js function requires a return value but value comes from callback so cannot be returned

From Dev

Cannot return the address of a cell range from one function to another, I get an 'object required' error

From Dev

C linkage function cannot return C++ class - error resulting from the contents of my method

From Dev

Cannot call value of non-function type 'JSON', How can I return value from block in Swift

From Dev

Function that returns an equation

Related Related

HotTag

Archive