01-11-2018, 09:13 PM

Hi there,

I'm trying to make a simple program to return an expression for the curvature of a single variable function in X. My intention would be to execute this in the home view and plot the result.

For a lot of functions this works just fine, but if I try it on the exponential function, I get some unexpected behavior.

When textbook display is enabled, the result seems exactly as expected, but once I copy it back to input, the (e^X)^2 term becomes e^(X)^2.

If I disable textbook display, we see that the function is actually returning e^(X)^2, which, strictly speaking, represents e^(X^2) instead of the desired e^(2X). If I evaluate the copied expression, you can even see that the extra parentheses are inserted afterwards to reflect this parsing:

I'm pretty sure the problem lies in the way my program is evaluating the return expression, but I'm unaware of how it should be written to ensure parentheses are always included before squaring the derivative.

Any insight would be much appreciated!

Thanks

I'm trying to make a simple program to return an expression for the curvature of a single variable function in X. My intention would be to execute this in the home view and plot the result.

Code:

`EXPORT CurvX(EX)`

BEGIN

LOCAL DEX=CAS.diff(EX,'X'), DDEX=CAS.diff(EX,'X',2);

RETURN (ABS(DDEX))/((1+(DEX)^(2))^(3/2));

END;

For a lot of functions this works just fine, but if I try it on the exponential function, I get some unexpected behavior.

When textbook display is enabled, the result seems exactly as expected, but once I copy it back to input, the (e^X)^2 term becomes e^(X)^2.

If I disable textbook display, we see that the function is actually returning e^(X)^2, which, strictly speaking, represents e^(X^2) instead of the desired e^(2X). If I evaluate the copied expression, you can even see that the extra parentheses are inserted afterwards to reflect this parsing:

I'm pretty sure the problem lies in the way my program is evaluating the return expression, but I'm unaware of how it should be written to ensure parentheses are always included before squaring the derivative.

Any insight would be much appreciated!

Thanks