Merge branch 'master' into bug-4403-remove-polyfill
[maxima.git] / archive / share / trash / differ.dem
blobd5449ab51ed07de5eaa22d8bc4d5340b65e44dd2
1 /*  Sample usage of difference equation package  -*-Macsyma-*- */
2 if get('differ,'version)=false then load(differ)$
4 a:matrix([1,-1],[-5,5]);
5 eigenvalues(a);
6 eigenvector(a,0);
7 eigenvector(a,6);
8 normalize:true$
9 eigenvector(a,0);
11 /*  First order equations  */
13 f[n+1]=f[n];
14 difference(%,f[n]);
16 g[0]:1$
17 g[n+1]=2*g[n];
18 difference(%,g[n]);
20 h[n+1]=3*h[n]+2;
21 difference(%,h[n]);
23 /*  Systems of homogeneous first order equations  */
25 differverbose:true$
26 eqn1:y[k+1]+z[k]-3*y[k]=0;
27 eqn2:3*y[k]+z[k+1]-5*z[k]=0;
28 difference([eqn1,eqn2],[y[k],z[k]]);
30 /*  Second order equations */
32 y[k+2]-6*y[k+1]+8*y[k]=0;
33 difference(%,y[k]);
35 differverbose:false$
37 y[0]:3$
38 y[1]:2$
39 y[k+2]-6*y[k+1]+8*y[k]=0;
40 difference(%,y[k]);
41 part(%,2),k=5;
43 /*  Fibonacci Numbers:   1, 1, 2, 3, 5, 8, 13, 21, ...  */
45 f[0]:1$
46 f[1]:1$
47 f[n+2]=f[n+1]+f[n];
48 difference(%,f[n]);
49 ratsimp(ev(part(%,2),n=7));
51 /* Cleanup */
53 remvalue(a);