Jesper,
You did not mention what version of JMP you are using. JMP 12 and higher have both integrate() and symbolic derivative() functions.
Attached is an example . It does not create the asymptotic linear formual just a simple linear. But teh goal of this script is to demo syntax. To reference symbolic formulas, they need to be expressions. In tehscripting Index, you should look up:
- Substitute(), NameExpr, EvalInsert(), Parse(), Simplify() , and
- of course, Integrate(), Derivative(). Note for the integrate function use an empty (dot) to specify infinity.
The results of the test cases are written to the Log window, and shown in the second code window.
You should post your final version. It looks like a cool function.
Names Default to Here(1);
//I think you meant you wanted a formula.
//The Jesper Function just finds the linear function, not the asymptotic linear function ... this code is a syntax example.
funList = {2*x+3, 2^x + 3, 2*sqrt(x)+1.2}; //test case for 3 formulas for x1=1 and x2=2, i.e. cntr=1.5, delta=0.5
Jesper = Function({form_xp, cntr, delta}, {x1, x2, y1, y2, m, b, err_xp, err, deriv },
x1 = cntr - delta;
x2 = cntr + delta;
y1 = Eval( Substitute(NameExpr(form_xp), Expr(x), x1 ));
y2 = Eval( Substitute(NameExpr(form_xp), Expr(x), x2 ));
m = (y2-y1)/(x2-x1) ;
b = y2 - m*x2;
lin_xp = Parse( EvalInsert( "^m^*x + ^b^"));
err_xp = Substitute(Expr((a)-(b)), Expr(a), NameExpr(form_xp), Expr(b), NameExpr(lin_xp) );
err_xp = SimplifyExpr(NameExpr(err_xp));
err = 1/(2*delta) * Eval ( Substitute( NameExpr(Integrate(_xp, x, _lo, _hi)), Expr(_xp), NameExpr(err_xp), Expr(_lo), x1, Expr(_hi), x2) );
deriv = Derivative(NameExpr(form_xp), x);
Eval List({err, NameExpr(form_xp), NameExpr(lin_xp), NameExpr(err_xp), NameExpr(deriv)});
);
for(i=1 ,i<=nitems(funlist), i++,
{err, func_xp, line_xp, err_xp, deriv_xp} =Jesper(funlist[i], 1.5, .5);
show(i, err, func_xp, line_xp, err_xp, deriv_xp);
write("\!N" ||Repeat("-", 80) );
);
The results from these 3 formulas are
/*:
i = 1;
err = 0;
func_xp = 2 * x + 3;
line_xp = 2 * x + 3;
err_xp = 0;
deriv_xp = 2;
--------------------------------------------------------------------------------
i = 2;
err = -0.114609918222073;
func_xp = 2 ^ x + 3;
line_xp = 2 * x + 3;
err_xp = -2 * x + 2 ^ x;
deriv_xp = 2 ^ x * Log(2);
--------------------------------------------------------------------------------
i = 3;
err = 0.0236892706214399;
func_xp = 2 * Sqrt(x) + 1.2;
line_xp = 0.82842712474619 * x + 2.37157287525381;
err_xp = (-1.17157287525381) + -0.82842712474619 * x + 2 * Sqrt(x);
deriv_xp = 2 * (0.5 / Sqrt(x));
--------------------------------------------------------------------------------