Post Reply 
Existing CAS commands --> Prime discussion
10-27-2018, 01:36 AM
Post: #32
RE: Existing CAS commands --> Prime discussion
hello in the following article shows some screenshots, where the history is used as a document file, the PC version of Xcas can incorporate comments in the history / * ... * /, I think this is very important to show contained in the classroom.

Using ClassPad-technology in the education of students of electrical
engineering (Fourier- and Laplace-Transformation)
Source: http://math.unipa.it/~grim/21_project/Paditz469-474.pdf

un sample on xcas

PHP Code:
/* File: Xcas Text */
/* Abstract: This document explains how to run efficiently CAS on HP Prime calculators. 
HP Prime CAS is an adapted version of the Giac/Xcas Computer Algebra System (CAS) for this calculator: */
/* Source: https://www-fourier.ujf-grenoble.fr/~parisse/casio/khicasioen.html */

/* 3. Common CAS commands */
/* [Tools] [CAS] [1: Algebra] */
/* 3.1 Expand and factor */
/* factor menu: [Tools] [CAS] [1] [4: Factor] */
/* ** factor: factorization. Shortcut cmd =>* (> key menu, then *), for example */
factor(x^4-1
x^4-1=>*
/* run cfactor to factor over Complex */
cfactor(x^4-1)
/* partfrac menu: [Tools] [CAS] [1] [7:Partial Fraction] */
/* ** partfrac: expands a polynomial or performs partial fraction expansion over a fraction. Shortcut =>+ (> key menu, then + key), for example */
partfrac((x+1)^4)
(
x+1)^4=>+ 
autosimplify(0):;partfrac(1/(x^4-1)) //(1/4)/(x-1) - (1/4)/(x+1) - (1/2)/(x²-1)
autosimplify(0):;1/(x^4-1)=>+
/* simplify menu: [Tools] [CAS] [1] [1: Simplify] */
/* ** simplify: tries to simplify an expression. Shortcut =>/ (> key menu, then /), for example */
simplify(sin(3x)/sin(x))
sin(3x)/sin(x)=>/ // Error syntax hp-prime when entry: textBook (pretty print or 2D)
/* ** ratnormal: rewrite as an irreducible fraction */
ratnormal((x^2-1)/(x^3-1))

/* 3.2 Calculus */
/* [Tools] [CAS] [2: Calculus] */
/* diff menu: [Tools] [CAS] [2] [1: Differentiate ] */
/* ** derivative. Shortcut ' (Shift [9] ') for derivative with respect to x, example */
angle_radian(1):;diff(sin(x),x
sin(x)'
/* For n th-derivative, add n, for example 3rd derivative */
diff(sin(x^2),x,3)
diff(sin(x²),x,3)
diff(sin(x³),x,3)

/* integrate menu: [Tools] [CAS] [2] [2: Integrate] */
/* ** integrate: antiderivative (1 or 2 arguments) for example */
integrate(sin(x)) 
integrate(1/(t^4-1),t) 
integrate(sin(x)^4,x,0,pi) 
/* For an approximate computation, enter one boundary as an approx number, for example */
integrate(sin(x)^4,x,0.0,pi) 

/* limit menu: [Tools] [CAS] [2] [3: Limit] */
/* ** limit of an expression. Example */
limit((cos(x)-1)/x^2,x=0) 

/* ** tabvar : table of variations of an expression. for example */
tabvar(x^3-7x+5) 
ClrIO:; plotfunc(x^3-7x+5,x,-4,4):;
DispG

/* taylor and series menu: [Tools] [CAS] [2] [8: Limits] [2: Taylor] */
/* ** taylor: Taylor expansion or asymptotic serie expansion, for example */
taylor(sin(x),x=0,5)
/* Add polynomial if you do not want to have the remainder term */
taylor(sin(x),x=0,5,polynom)

/* sum menu: [Tools] [CAS] [2] [5: Summation] */
/* ** sum: discrete summation, for example */
sum(k^2,k,1,n) 
/* computes the sum and rewrites it factored. */
sum(k^2,k,1,n)=>* 

/* 3.3 Solvers */
/* solve menu: [Tools] [CAS] [3: Solve] */
/* ** solve: solve solves an equation exactly. Takes the variable to solve for as second argument, unless it is x, for example */
solve(t^2-1=0,t) 
solve(t^2-1=0,t,'
=') 
/* If exact solving fails, run fsolve for approx solving, either with an iterative method starting with a guess */
fsolve(cos(x)=x,x=0.0) 
/* or by dichotomy */
fsolve(cos(x)=x,x=0..1) 
/* For complex solutions, run csolve */
csolve(x^4-1=0,x,'
=') 

/* It is possible to restrict solutions using assumptions on the variable, for example */
assume(m>1) // then
solve(m^2-4=0,m) 
purge(m):; 
solve(m^2-4=0,m) 
/* ** solve can also solve (simple) polynomial systems, enter a list of equations as 1st argument and a list of variables as 2nd argument, for example intersection of a circle and a line: */
solve([x^2+y^2+2y=3,x+y=1],[x,y])
solve([x^2+y^2+2y=3,x+y=1],[x,y],'
=')
/* ** Run linsolve to solve linear systems. enter a list of equations as 1st argument and a list of variables as 2nd argument, example: */
linsolve([x+2y=3,x-y=7],[x,y])
/* ** Run desolve to solve exactly a differential equation. for example, to solve y'
=2y */
desolve(y'=2y)
/* Another example with an initial condition: */
desolve([y'
=2*y,y(0)=1],x,y// bug desolve([y'=2*y,y[0]=1],x,y)
/* ** Run odesolve for approx solving or plotode for a graphic representation of the approx. solution. */
/* ** rsolve solves some recurrence relations u(n+1)=f(un,..), for example to solve the arithmetico-geometric recurrence */
rsolve(u(n+1)=2*u(n)+3,u(n),u(0)=1)

/* 3.4 Arithmetic */
/* When required, the distinction between integer arithmetic and polynomial arithmetic is done by a prefix i for integer commands. For example ifactor for integer factorization and factor for polynomial factorization */
/* (or cfactor for polynomial factorization over Complex). Some commands work for integers and polynomials, like gcd and lcm */
/* 3.4.1 IInteger */
/* quotient menu: [Tools] [CAS][5: Integer][7: Division][1: Quotient] */
/* ** iquo(a,b), irem(a,b) quotient and remainder of euclidean division of two integers. */
iquo(23,13),irem(23,13)
/* ** isprime(n) checks whether n is prime. This is a probabilisitic test for large values of n */
isprime(2^64+1
/* ** ifactor(n) factorizes an integer (not too large, since algorithms used are trial division and Pollard-ρ, there is no space left in memory for quadratic sieve), for example */
ifactor(2^64+1
2^64+1
approx
(ifactor(2^64+1))
/* ** gcd(a,b), lcm(a,b) GCD and LCM of two integers or polynomials. */
gcd(25,15),lcm(25,15
gcd(x^3-1,x^2-1),lcm(x^3-1,x^2-1)
/* ** iegcd(a,b) returns 3 integers u,v,d such that a·u+b·v=d where d is the GCD of a and b, |u| and |v|<|a|. */
u,v,d:=iegcd(23,13); 23u+13v 
purge
(u,v,d):;
/* ** ichinrem([a,m],[b,n]) returns (if possible) c such that c=a (mod m) and c=b (mod n) (if m are n coprime, c exists). */
c,n:=ichinrem([1,23],[2,13]);irem(c,23); irem(c,13
purge(c,n):;
/* ** powmod(a,n,m) returns a^n(mod m) computed by the fast modular powering algorithm */
powmod(7,22,23
/* ** asc converts a string to a list of ASCII code, char converts back a list to a string. These commands may be used to easily write cryptographic algorithms with string messages. */
asc("A"), asc("123+4")

/* 3.4.2 Polynomials */
/* From catalog, select Polynomials. The default variable is x, otherwise you can specify it as last optional argument. For example degree(x²·y) or degree(x²·y,x) return 2, degree(x²·y,y) returns 1. */
/* ** coeff(P,n) coefficient of x^n in P, lcoeff(P) leading coefficient of P, for example */
P_:=x^3+3xcoeff(P_,1); lcoeff(P_)
purge(P_):;
/* ** degre(P) degree of polynomial P */
degree(x^3)
/* ** quo(P,Q), rem(P,Q) quotient and remainder of euclidean division of P by Q */
P_:=x^3+7x-5Q_:=x^2+xquo(P_,Q_); rem(P_,Q_

purge(P_,Q_):;
/* ** proot(P): approx. roots of P (all roots, real and complex) */
proot(x^5+x+1)

/* Graphic representation */
ClrIOpoint(proot(x^5+x+1)):;
DispG
/* ** interp(X,Y): for two lists of the same size, returns the interpolating polynomial P such that P(X_i)=Y_i. */
X_,Y_:=[0,1,2,3],[1,-3,-2,0];P_:=interp(X_,Y_)=>+
/* Graphic representation */
ClrIO:; scatterplot(X_,Y_); plotfunc(P_,x,-1,4):;
/* ** resultant(P,Q) : resultant of polynomials P and Q */
purge(X_,Y_):; P_:=x^3+7x-5Q_:=x^2+xresultant(P_,Q_)
purge(P_,Q_):;
/* ** hermite(x,n): n-th Hermite polynomial (orthogonal for the density e^(−x²)dx on R) */
hermite(3)
/* ** laguerre(x,n,a): n-th Laguerre polynomial */
laguerre(4)
/* ** legendre(x,n) */
legendre(4)
/* ** tchebyshev1(n) and tchebyshev2(n) */
tchebyshev1(3)
tchebyshev2(3)

/* 3.5 Linear algebra, vectors, matrices */
/* Xcas does not make distinction between vectors and lists. For example, */
v:=[1,2]; w:=[3,4// defines 2 vectors v and w, then dot will compute the scalar product of v and w
dot(v,w)

/* .A matrix is a list of lists of the same size. You can enter a matrix element by element using the matrix editor (shift-4 or 2D template [c/units] key). 
Enter a new variable name to create a new matrix or the name of an existing variable to edit a matrix. 
For small matrices, it is also convenient to enter them directly in the commandline, for example to define */
A_:=[[1,2],[3,4]]
/* or */
[[1,2],[3,4]]=>A_
index
:=0
/* If a matrix is defined by a formula, then it’s better to use the matrix command, for example: */
matrix(2,2,(j,k)->1/(j+k+1)) 
/* returns the matrix where coefficient line j and column k is 1/(j+k+1) (beware, indices begin at 0). */
/* Run idn(n) to get the identity matrix of order n and ranm(n,m,law,[parameter]) to get a matrix with random coefficients with dimensions n,m. for example */
/* Line 1
Line 2
Line 3 */
U_:=ranm(4,4,uniformd,0,1
N_:=ranm(4,4,normald,0,1
purge(U_,N_):;

/* For basic arithmetic on matrices, use keyboard operators (+ - *, inverse). Otherwise, open catalog and select [Tools] [Math][7: Matrix] */
/* eigenvalues and eigenvectors of matrix A. */
A_:=[[1,2],[3,4]]; eigenvals(A// [Tools] [Math][7: Matrix][6: Advenced][1: Eigenvalues]
eigenvects(A_// [Tools] [Math][7: Matrix][6: Advenced][1: Eigenvectors]
/* finds the Jordan normal form of matrix A, returns matrices P and D such that P^−1·A·P=D, with D upper triangular (diagonal if A is diagonalizable) */
P_,D_:=jordan(A_
purge(P_,D_):;
/* computes matrix A to the k-th power, where k is symbolic. */
Ak:=matpow(A_,k
/* ** rref: row reduction to echelon form */
rref(A_)
/* ** lu: LU factorization of matrix A, returns a permutation P and two matrices L (lower) and U (upper) such that P·A=L·U. The result of */
P_,L_,U_:=lu(A_)
linsolve(P_,L_,U_,v)

/* to solve a system A·x=b by solving two triangular systems (in O(n²) instead of O(n³)). */
/* ** qr Q·R factorization of matrix A, Q is orthogonal and R upper triangular, A=Q·R */
/* ** svd(A) singular value decomposition of matrix A returns U orthogonal, S vector of singular values, Q orthogonal such that A=U·diag(S)·tran(Q). 
The ratio of the largest and the smallest singular value of S is the condition number of A relative to the Euclidean norm */
svd(A_)
purge(A_,P_,L_,U_,v,w):;
/* 4 Probabilities and statistics
4.1 Random numbers */
/* [Tools] [Math][5: Probability][4: Random][1: Number] */
rand() // (real in [0,1])
n:=6:; randint(n)
ranv(10,normald,0,1)
purge(n):;
/* 5 Graphics */
/* [Tools] [CAS][7: Plot][1: Function] */
/* ** plot(f(x),x=a..b) plot expression f(x) for x [a,b]. Discretization option: xstep=, for example */
ClrIOplotfunc(x^2,x=-4..4,xstep=1):;
DispG
/* Default is 384 evaluations per plot (one per horizontal pixel). */
/* ** plotseq(f(x),x=[u0,a,b]) webplot for a recurrent sequence u_(n+1)=f(u_n) of first term u_0, for example if u(n+1)=√(2+u_n),u_0=6, with a plot on [0,7] */
ClrIOplotseq(sqrt(2+x),x=[6,0,7]):; // color ?
DispG
/* ** plotparam([x(t),y(t)],t=tm..tM) parametric plot (x(t),y(t)) for t © [tm,tM]. Discretization option: tstep=. Example */
ClrIOplotparam([sin(2t),cos(3t)],t,0,2*pi):;
DispG

/* plotpolar(r(theta),theta=a..b) polar plot of r(θ) for θ © [a,b], for example */

ClrIOplotpolar(sin(3*theta),theta,0,2*pi):;
DispG
ClrIO
l:=ranv(500,normald,0,1); histogram(l,-4,0.25):; plotfunc(normald(x),x,-4,4):;

purge(l):;
ClrIOplotfield(sin(t*y),[t=-3..3,y=-3..3],plotode=[0,1]):;

ClrIOplotfunc(sin(x),x,display=red):;
ClrIOplotfunc(cos(x),x,color=green):;
/* 6 Programs */
/* Example : function defined by an algebraic expression nom_fonction(parametres):=expression for example simple confidence interval for a frequency p in a sample of size N */
F1_(P_,N_):=[P_-1/sqrt(N_), P_+1/sqrt(N_)]:;
/* test */
F1_(0.4,30)
/* Second example : more precise confidence interval for a frequency p in a sample of size N: */
f(P_,N_):=[P_-1.96*sqrt(P*(1-P_)/N_),P_+1.96*sqrt(P_*(1-P_)/N_)]:;

function 
f1(P,Nlocal DD:=1.96*sqrt(P*(1-P)/N); return [P-D,P+D]; ffunction

Source:https://www-fourier.ujf-grenoble.fr/~parisse/casio/khicasioen.html
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Existing CAS commands --> Prime discussion - compsystems - 10-27-2018 01:36 AM



User(s) browsing this thread: 3 Guest(s)