User Tools

Site Tools


prime:misctips

This is an old revision of the document!


Miscellaneous Tips

Note that there is a shortcut to STRING(V) by just doing T:=“”+V; However, STRING(V) is faster and uses less RAM.

When a loop must execute at least once, use REPEAT, otherwise use WHILE.

To get a single character from a string, S, there are several ways. S(3) returns an ASCII code. CHAR(S(3)) will return it as a string like “e”. S(3,1) returns a one character substring as in “e”. ASC(S(3,1)) is the same as S(3).

The \ character is generated from the Shift-Vars/Chars key. It's on the first page of characters.

When plotting a function where f(x) is complex over an interval, the graph will appear blank during that interval, as you cannot plot a complex value when there is only a real y-axis. Get the magnitude of the complex value and plot that instead.

To return multiple values, return it as a list. e.g. f1(x) returns a list containing 3 integers. The values returned can be assigned to variables like this: L:=f1(x);A:=L(1);B:=L(2);C:=L(3);

Use L(0) to index the tail of a list. To concatenate to a list, you can do something like L:={4,9,16};L(0):=√(L); That would result in L being {4,9,16,2,3,4}.

Indefinite integral has an implicit “+ constant” at the end of the results. In some CAS systems it's mentioned, but in the PRIME, it isn't. Note that this is so the result can be cut and pasted without having to delete the extra text, which is preferred. The constant is eliminated when the limits are provided for the definite integral. Note that the preval() function calculates f(b)-f(a), when called like preval(f,a,b[,var]), which can be used to get the definite integral from the indefinite integral.

When integrating in CAS, if you put a . after a limit (definite integral) it knows to use approximation, so you'd use 0. instead of 0 would force this. This also happens in some other functions too. Worth trying if you get undef from a calculation.

When working with trigonometric functions, there are a group of functions that can allow for simplification of terms, or expansion in a particular direction. trigcos() will try to express the expression in terms of cosines, similarly with trigsin, trigtan. Likewise, there are a set of functions to convert between exponents, trig and ln functions. simplify and trigexpand can be useful in such cases too. tcollect() can convert an expression involving powers of trig functions to functions of nx. Note that some of these functions can result in a constant at the end of the expression and if this is an indefinite integral result, then this constant can be thrown away without error. ratnormal() can combine multiple fractions into one simplest irreducible fraction. E.g. Calling integrate( (cos(2*x)^3)*(sin(2*x)^5), x ) results in -(1/16)*cos(2*x)^3-(1/6)*cos(2*x)^6-(1/8)*cos(2*x)^4. trigsin() of this result gives -(1/16)*sin(2*x)^8-(1/12)*sin(2*x)^6-(1/48). Calling ratnormal() on this gives us (-3*(sin(2*x))^8+4*(sin(2*x))^6-1)/48. If we wished, we could drop the 1/48 term, since it's an indefinite integral. So, dropping the constant and calling trigexpand on this, the result is -16*(cos(x)^8)*(sin(x)^8)-(16/3)*(cos(x)^6)*(sin(x)^6). Likewise, taking the original integral result and calling tcollect() on it, the result is -(3/256)*cos(4*x)-(1/512)*cos(8*x)-(1/768)*cos(12*x)-(1/2048)*cos(16*x)-(73/6144). Again, since it's an indefinite integral, the constant term at the end can be dropped.

In summary, have a trig expression and want to break it down to certain terms:

  • trigcos: Breaks it down in terms of cos.
  • trigsin: Breaks it down in terms of sin.
  • trigtan: Breaks it down in terms of tan.
  • tcollect: Converts from powers of trig functions to functions of n*x. Converts products to sums.
  • trigexpand: Converts to expression in terms of sin(x) and cos(x).
  • ratnormal: Changes different fractions in each term to one big irreducible fraction.

TEVAL(func_call()) returns the time it takes to run func_call in seconds in 2.5_s units. Since this format isn't a real, it cannot be assigned to the global REAL variables like A,B,C,etc.. in Home mode. There is an undocumented time() function that just returns a REAL value that can be used in both Home and CAS mode. It's undocumented so it could disappear in a future release of the firmware. Note that due to the timer tick being 1ms, and due to timer functions to get the battery value, LCD refresh, etc, etc, timer values under 100ms should be taken with a grain of salt. You can put the function call in a loop that takes over a second to execute, then you can compare the values returned with a bit more confidence.

prime/misctips.1509375796.txt.gz · Last modified: 2017/10/30 08:03 by webmasterpdx