function with parameters

15 views
Skip to first unread message

Cyrille Piatecki

unread,
Jan 3, 2025, 11:33:35 AMJan 3
to JSXGraph
Since two days we struggle with a function phi(x,m,s).

It seems impossible to fix m and s to some value and to use functiongraph since function graph works with the variable implicitely defined (without reference to the variable). In the case of the Laplace-Gauss density function we have tried

class fct_phi {
    constructor(s,m) {
        this.m=m;
        this.s=s;
    }
    phi(x) {
        return (1/(Math.pow(2*Math.PI,1/2)*this.s))*Math.pow(Math.exp(1),-(1/2)*Math.pow((x-this.m)/this.s,2));
    }
};

f=new fct_phi(1,0);
board.create('functiongraph',[f.phi,-1,1],{strokeColor:"red"});

but obviously it doesn't display any thing sinece the function is not evaluated.


Tom Berend

unread,
Jan 3, 2025, 3:08:33 PMJan 3
to jsxg...@googlegroups.com
Dear Cyrille,

Try this:    board.create('functiongraph', [(x) => f.phi(x), -1, 1], { strokeColor: "red" });

Regards
Tom

--
You received this message because you are subscribed to the Google Groups "JSXGraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsxgraph+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jsxgraph/cc25a4ae-5a12-488c-94f5-9141a170e5d2n%40googlegroups.com.

Cyrille Piatecki

unread,
Jan 5, 2025, 10:31:08 AMJan 5
to JSXGraph
Thanks Tom.
Reply all
Reply to author
Forward
0 new messages