~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to tests/rtest3.mac

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
 
9
9
/* rtest3 */                                            
10
 
kill(allbut(props));
 
10
kill(all);
11
11
done;
12
 
FOR A FROM -3 STEP 7 THRU 26 DO LDISPLAY(A);
13
 
DONE$
14
 
S:0;
 
12
for a from -3 step 7 thru 26 do ldisplay(a);
 
13
done$
 
14
s:0;
15
15
0$
16
 
FOR I WHILE I <= 10 DO S:S+I;
17
 
DONE$
18
 
S;
 
16
for i while i <= 10 do s:s+i;
 
17
done$
 
18
s;
19
19
55$
20
 
SERIES:1;
 
20
series:1;
21
21
1$
22
 
TERM:EXP(SIN(X));
23
 
%E^SIN(X)$
24
 
FOR P UNLESS P > 7 DO
25
 
    (TERM:DIFF(TERM,X)/P,SERIES:SERIES+SUBST(X = 0,TERM)*X^P);
26
 
DONE$
27
 
SERIES;
28
 
X^7/90-X^6/240-X^5/15-X^4/8+X^2/2+X+1$
29
 
POLY:0;
 
22
term:exp(sin(x));
 
23
%e^sin(x)$
 
24
for p unless p > 7 do
 
25
    (term:diff(term,x)/p,series:series+subst(x = 0,term)*x^p);
 
26
done$
 
27
series;
 
28
x^7/90-x^6/240-x^5/15-x^4/8+x^2/2+x+1$
 
29
poly:0;
30
30
0$
31
 
FOR I THRU 5 DO (FOR J FROM I STEP -1 THRU 1 DO POLY:POLY+I*X^J);
32
 
DONE$
33
 
POLY;
34
 
5*X^5+9*X^4+12*X^3+14*X^2+15*X$
35
 
GUESS:-3.0;
 
31
for i thru 5 do (for j from i step -1 thru 1 do poly:poly+i*x^j);
 
32
done$
 
33
poly;
 
34
5*x^5+9*x^4+12*x^3+14*x^2+15*x$
 
35
guess:-3.0;
36
36
-3.0$
37
 
FOR I THRU 10 DO
38
 
    (GUESS:SUBST(GUESS,X,0.5*(X+10/X)),
39
 
     IF ABS(GUESS^2-10) < 5.0E-5 THEN RETURN(GUESS));
 
37
for i thru 10 do
 
38
    (guess:subst(guess,x,0.5*(x+10/x)),
 
39
     if abs(guess^2-10) < 5.0e-5 then return(guess));
40
40
-3.162280701754386;
41
41
/* -3.1622806$ */
42
 
FOR COUNT FROM 2 NEXT 3*COUNT THRU 20 DO LDISPLAY(COUNT);
43
 
DONE$
44
 
X:1000;
 
42
for count from 2 next 3*count thru 20 do ldisplay(count);
 
43
done$
 
44
x:1000;
45
45
1000$
46
 
THRU 10 WHILE X # 0 DO X:0.5*(X+5/X);
47
 
DONE$
48
 
X;
 
46
thru 10 while x # 0 do x:0.5*(x+5/x);
 
47
done$
 
48
x;
49
49
2.28242904$
50
 
REMVALUE(X);
51
 
[X]$
52
 
NEWTON(F,GUESS):=BLOCK([NUMER,Y],LOCAL(F,DF,X,GUESS),NUMER:TRUE,
53
 
       DEFINE(DF(X),DIFF(F(X),X)),
54
 
       DO (Y:DF(GUESS),IF Y = 0 THEN ERROR("derivative at",GUESS,"is zero"),
55
 
           GUESS:GUESS-F(GUESS)/Y,
56
 
           IF ABS(F(GUESS)) < 5.0E-6 THEN RETURN(GUESS)));
57
 
NEWTON(F,GUESS):=BLOCK([NUMER,Y],LOCAL(F,DF,X,GUESS),NUMER:TRUE,
58
 
       DEFINE(DF(X),DIFF(F(X),X)),
59
 
       DO (Y:DF(GUESS),IF Y = 0 THEN ERROR("derivative at",GUESS,"is zero"),
60
 
           GUESS:GUESS-F(GUESS)/Y,
61
 
           IF ABS(F(GUESS)) < 5.0E-6 THEN RETURN(GUESS)))$
62
 
SQR(X):=X^2-5.0;
63
 
SQR(X):=X^2-5.0$
64
 
NEWTON(SQR,1000);
 
50
remvalue(x);
 
51
[x]$
 
52
newton(f,guess):=block([numer,y],local(f,df,x,guess),numer:true,
 
53
       define(df(x),diff(f(x),x)),
 
54
       do (y:df(guess),if y = 0 then error("derivative at",guess,"is zero"),
 
55
           guess:guess-f(guess)/y,
 
56
           if abs(f(guess)) < 5.0e-6 then return(guess)));
 
57
newton(f,guess):=block([numer,y],local(f,df,x,guess),numer:true,
 
58
       define(df(x),diff(f(x),x)),
 
59
       do (y:df(guess),if y = 0 then error("derivative at",guess,"is zero"),
 
60
           guess:guess-f(guess)/y,
 
61
           if abs(f(guess)) < 5.0e-6 then return(guess)))$
 
62
sqr(x):=x^2-5.0;
 
63
sqr(x):=x^2-5.0$
 
64
newton(sqr,1000);
65
65
2.236068027062195; 
66
 
FOR F IN [LOG,RHO,ATAN] DO LDISP(F(1.0));
67
 
DONE$
68
 
EV(CONCAT(E,LINENUM-1),NUMER);
69
 
E10$
70
 
KILL(FUNCTIONS,VALUES,ARRAYS);
71
 
DONE$
72
 
DONE;
73
 
DONE$
74
 
EXP:DIFF(X*F(X),X);
75
 
X*'DIFF(F(X),X,1)+F(X)$
76
 
F(X):=SIN(X);
77
 
F(X):=SIN(X)$
78
 
EV(EXP,DIFF);
79
 
SIN(X)+X*COS(X)$
80
 
X;
81
 
X$
82
 
X:3;
83
 
3$
84
 
X;
85
 
3$
86
 
'X;
87
 
X$
88
 
F(X):=X^2;
89
 
F(X):=X^2$
90
 
'F(2);
91
 
'F(2)$
92
 
EV(%,F);
93
 
4$
94
 
'(F(2));
95
 
F(2)$
96
 
F(2);
97
 
4$
98
 
SUM(I!,I,1,4);
 
66
for f in [log,rho,atan] do ldisp(f(1.0));
 
67
done$
 
68
ev(concat(e,linenum-1),numer);
 
69
e10$
 
70
kill(functions,values,arrays);
 
71
done$
 
72
done;
 
73
done$
 
74
exp:diff(x*f(x),x);
 
75
x*'diff(f(x),x,1)+f(x)$
 
76
f(x):=sin(x);
 
77
f(x):=sin(x)$
 
78
ev(exp,diff);
 
79
sin(x)+x*cos(x)$
 
80
x;
 
81
x$
 
82
x:3;
 
83
3$
 
84
x;
 
85
3$
 
86
'x;
 
87
x$
 
88
f(x):=x^2;
 
89
f(x):=x^2$
 
90
'f(2);
 
91
'f(2)$
 
92
ev(%,f);
 
93
4$
 
94
'(f(2));
 
95
f(2)$
 
96
f(2);
 
97
4$
 
98
sum(i!,i,1,4);
99
99
33$
100
 
'SUM(I!,I,1,4);
101
 
'SUM(I!,I,1,4)$
102
 
REMVALUE(X);
103
 
[X]$
104
 
'INTEGRATE(F(X),X,A,B);
105
 
'INTEGRATE(X^2,X,A,B)$
106
 
FOR I THRU 5 DO S:S+I^2;
107
 
DONE$
108
 
EXP:S;
109
 
S+55$
110
 
EV(%,S:0);
 
100
'sum(i!,i,1,4);
 
101
'sum(i!,i,1,4)$
 
102
remvalue(x);
 
103
[x]$
 
104
'integrate(f(x),x,a,b);
 
105
'integrate(x^2,x,a,b)$
 
106
for i thru 5 do s:s+i^2;
 
107
done$
 
108
exp:s;
 
109
s+55$
 
110
ev(%,s:0);
111
111
55$
112
 
EV(EXP);
113
 
S+110$
114
 
EXP:'SUM(G(I),I,0,N);
115
 
'SUM(G(I),I,0,N)$
116
 
Z*%E^Z;
117
 
Z*%E^Z$
118
 
EV(%,Z:X^2);
119
 
X^2*%E^X^2$
120
 
SUBST(X^2,Z,EXP);
121
 
'SUM(G(I),I,0,N)$
122
 
A:%;
123
 
'SUM(G(I),I,0,N)$
124
 
A+1;
125
 
'SUM(G(I),I,0,N)+1$
126
 
KILL(A,Y);
127
 
DONE$
128
 
A;
129
 
A$
130
 
DECLARE(INTEGRATE,NOUN);
131
 
DONE$
132
 
INTEGRATE(Y^2,Y);
133
 
INTEGRATE(Y^2,Y)$
134
 
''INTEGRATE(Y^2,Y);
135
 
Y^3/3$
136
 
F(Y):=DIFF(Y*LOG(Y),Y,2);
137
 
F(Y):=DIFF(Y*LOG(Y),Y,2)$
138
 
F(Y):=1/Y;
139
 
F(Y):=1/Y$
140
 
C10;
141
 
C10$
142
 
(X+Y)^3;
143
 
(Y+X)^3$
144
 
DIFF(%,X);
145
 
3*(Y+X)^2$
146
 
Y:X^2+1;
147
 
X^2+1$
 
112
ev(exp);
 
113
s+110$
 
114
exp:'sum(g(i),i,0,n);
 
115
'sum(g(i),i,0,n)$
 
116
z*%e^z;
 
117
z*%e^z$
 
118
ev(%,z:x^2);
 
119
x^2*%e^x^2$
 
120
subst(x^2,z,exp);
 
121
'sum(g(i),i,0,n)$
 
122
a:%;
 
123
'sum(g(i),i,0,n)$
 
124
a+1;
 
125
'sum(g(i),i,0,n)+1$
 
126
kill(a,y);
 
127
done$
 
128
a;
 
129
a$
 
130
declare(integrate,noun);
 
131
done$
 
132
integrate(y^2,y);
 
133
integrate(y^2,y)$
 
134
''integrate(y^2,y);
 
135
y^3/3$
 
136
f(y):=diff(y*log(y),y,2);
 
137
f(y):=diff(y*log(y),y,2)$
 
138
f(y):=1/y;
 
139
f(y):=1/y$
 
140
c10;
 
141
c10$
 
142
(x+y)^3;
 
143
(y+x)^3$
 
144
diff(%,x);
 
145
3*(y+x)^2$
 
146
y:x^2+1;
 
147
x^2+1$
148
148
 
149
149
/* begin fix */
150
 
kill(allbut(props));
 
150
kill(all);
151
151
done;
152
 
 EV(%E^X*SIN(X)^2,EXPONENTIALIZE);
153
 
 -%E^X*(%E^(%I*X)-%E^-(%I*X))^2/4;
154
 
  integrate(%,X);
155
 
-(%E^((2*%I+1)*X)/(2*%I+1)+%E^((1-2*%I)*X)/(1-2*%I)-2*%E^X)/4; 
156
 
 EV(%,DEMOIVRE);
157
 
 -(%E^X*(%I*SIN(2*X)+COS(2*X))/(2*%I+1)
158
 
      +%E^X*(COS(2*X)-%I*SIN(2*X))/(1-2*%I)-2*%E^X)
 
152
 ev(%e^x*sin(x)^2,exponentialize);
 
153
 -%e^x*(%e^(%i*x)-%e^-(%i*x))^2/4;
 
154
  integrate(%,x);
 
155
-(%e^((2*%i+1)*x)/(2*%i+1)+%e^((1-2*%i)*x)/(1-2*%i)-2*%e^x)/4; 
 
156
 ev(%,demoivre);
 
157
 -(%e^x*(%i*sin(2*x)+cos(2*x))/(2*%i+1)
 
158
      +%e^x*(cos(2*x)-%i*sin(2*x))/(1-2*%i)-2*%e^x)
159
159
      /4;
160
 
 ANS:EV(%,RATEXPAND);
161
 
 -%E^X*SIN(2*X)/5-%E^X*COS(2*X)/10+%E^X/2;
162
 
 EV(ANS,X:1,NUMER)-EV(ANS,X:0,NUMER);
 
160
 ans:ev(%,ratexpand);
 
161
 -%e^x*sin(2*x)/5-%e^x*cos(2*x)/10+%e^x/2;
 
162
 ev(ans,x:1,numer)-ev(ans,x:0,numer);
163
163
 0.5779160182042402;
164
 
 block([FPPREC:35],EV(ANS,X:1,BFLOAT)-EV(ANS,X:0,BFLOAT));
165
 
 5.7791601820424019599988308251707781339427227258443B-1;
166
 
 INTEGRATE(%E^X*SIN(X)^2,X);
167
 
 -(2*%E^X*SIN(2*X)+%E^X*COS(2*X)-5*%E^X)/10;
 
164
 block([fpprec:35],ev(ans,x:1,bfloat)-ev(ans,x:0,bfloat));
 
165
 5.7791601820424019599988308251707781339427227258443b-1;
 
166
 integrate(%e^x*sin(x)^2,x);
 
167
 -(2*%e^x*sin(2*x)+%e^x*cos(2*x)-5*%e^x)/10;
168
168
 trigreduce(%);
169
 
 -(2*%E^X*SIN(2*X)+%E^X*COS(2*X)-5*%E^X)/10;
 
169
 -(2*%e^x*sin(2*x)+%e^x*cos(2*x)-5*%e^x)/10;
170
170
 % - ans,ratsimp;
171
171
 0 ;
172
172
 
173
173
/* end fix*/
174
174
 
175
 
EV(SIN(X),%EMODE);
176
 
SIN(X)$
177
 
SIN(%PI/12)+TAN(%PI/6);
178
 
SIN(%PI/12)+1/SQRT(3)$
179
 
EV(%,NUMER);
 
175
ev(sin(x),%emode);
 
176
sin(x)$
 
177
sin(%pi/12)+tan(%pi/6);
 
178
sin(%pi/12)+1/sqrt(3)$
 
179
ev(%,numer);
180
180
0.8361693142921465;
181
181
/* tops 20 : 0.83616931$ */
182
 
SIN(1);
183
 
SIN(1)$
184
 
EV(SIN(1),NUMER);
 
182
sin(1);
 
183
sin(1)$
 
184
ev(sin(1),numer);
185
185
0.8414709848079;
186
 
BETA(1/2,2/5);
187
 
BETA(1/2,2/5)$
188
 
EV(%,NUMER);
 
186
beta(1/2,2/5);
 
187
beta(1/2,2/5)$
 
188
ev(%,numer);
189
189
3.679093980405881;
190
190
/* tops 20: 3.67909265$ */
191
 
DIFF(ATANH(SQRT(X)),X);
192
 
1/(2*(1-X)*SQRT(X))$
193
 
FPPREC:25;
 
191
diff(atanh(sqrt(x)),x);
 
192
1/(2*(1-x)*sqrt(x))$
 
193
fpprec:25;
194
194
25$
195
 
SIN(5.0B-1);
196
 
4.794255386042030002732879B-1$
 
195
sin(5.0b-1);
 
196
4.794255386042030002732879b-1$
197
197
/*begin fix */
198
 
 EXP:COS(X)^2-SIN(X)^2;
199
 
 COS(X)^2-SIN(X)^2$
200
 
 EV(%,X:%PI/3);
 
198
 exp:cos(x)^2-sin(x)^2;
 
199
 cos(x)^2-sin(x)^2$
 
200
 ev(%,x:%pi/3);
201
201
 -1/2$
202
 
 DIFF(EXP,X);
203
 
 -4*COS(X)*SIN(X)$
204
 
 INTEGRATE(EXP,X);
205
 
 (SIN(2*X)/2+X)/2-(X-SIN(2*X)/2)/2$
206
 
 EXPAND(%);
207
 
 SIN(2*X)/2$
208
 
 TRIGEXPAND(%);
209
 
 COS(X)*SIN(X)$
210
 
 TRIGREDUCE(%);
211
 
 SIN(2*X)/2$
212
 
 diff(%,X);
213
 
 COS(2*X)$
 
202
 diff(exp,x);
 
203
 -4*cos(x)*sin(x)$
 
204
 integrate(exp,x);
 
205
 (sin(2*x)/2+x)/2-(x-sin(2*x)/2)/2$
 
206
 expand(%);
 
207
 sin(2*x)/2$
 
208
 trigexpand(%);
 
209
 cos(x)*sin(x)$
 
210
 trigreduce(%);
 
211
 sin(2*x)/2$
 
212
 diff(%,x);
 
213
 cos(2*x)$
214
214
 %-exp,trigreduce,ratsimp;
215
215
  0;
216
216
/*end fix*/
217
 
SECH(X)^2*SINH(X)*TANH(X)/COTH(X)^2+COSH(X)^2*SECH(X)^2*TANH(X)/COTH(X)^2
218
 
                                   +SECH(X)^2*TANH(X)/COTH(X)^2;
219
 
SECH(X)^2*SINH(X)*TANH(X)/COTH(X)^2+COSH(X)^2*SECH(X)^2*TANH(X)/COTH(X)^2
220
 
                                   +SECH(X)^2*TANH(X)/COTH(X)^2$
221
 
TRIGSIMP(%);
222
 
(SINH(X)^5+SINH(X)^4+2*SINH(X)^3)/COSH(X)^5$
 
217
sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2
 
218
                                   +sech(x)^2*tanh(x)/coth(x)^2;
 
219
sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2
 
220
                                   +sech(x)^2*tanh(x)/coth(x)^2$
 
221
trigsimp(%);
 
222
(sinh(x)^5+sinh(x)^4+2*sinh(x)^3)/cosh(x)^5$
 
223
/* These are from the trgsmp.dem file.  
 
224
 * I (rtoy) hand-verified these results (using maxima, of course)
 
225
 */
 
226
(1-sin(x)^2)*cos(x)/cos(x)^2+tan(x)*sec(x)^2;
 
227
(1-sin(x)^2)*cos(x)/cos(x)^2+tan(x)*sec(x)^2$
 
228
trigsimp(%);
 
229
(sin(x)+cos(x)^4)/cos(x)^3$
 
230
 
 
231
tan(x)^2+sec(x)^2/(1-tan(x)*sec(x));
 
232
tan(x)^2+sec(x)^2/(1-tan(x)*sec(x))$
 
233
trigsimp(%);
 
234
(sin(x)^4+sin(x)^3-1)/(cos(x)^2*sin(x)-cos(x)^4)$
 
235
 
 
236
(sin(x)^4-6*cos(x)^2*sin(x)^2+4*(cos(x)^2-sin(x)^2)+8*sin(x)+cos(x)^4+3)/(8*cos(x)^3);
 
237
(sin(x)^4-6*cos(x)^2*sin(x)^2+4*(cos(x)^2-sin(x)^2)+8*sin(x)+cos(x)^4+3)/(8*cos(x)^3)$
 
238
trigsimp(%);
 
239
(sin(x)+cos(x)^4)/cos(x)^3$
 
240
 
 
241
 
 
242
sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2+sech(x)^2*tanh(x)/coth(x)^2;
 
243
sech(x)^2*sinh(x)*tanh(x)/coth(x)^2+cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2+sech(x)^2*tanh(x)/coth(x)^2$
 
244
trigsimp(%);
 
245
(sinh(x)^5+sinh(x)^4+2*sinh(x)^3)/cosh(x)^5$
 
246
 
 
247
-sech(x)^5*(sinh(x)^5+2*(sinh(x)^4+6*cosh(x)^2*sinh(x)^2+cosh(x)^4)-13*(sinh(x)^3+3*cosh(x)^2*sinh(x))+10*cosh(x)^2*sinh(x)^3-8*(sinh(x)^2+cosh(x)^2)+5*cosh(x)^4*sinh(x)+34*sinh(x)+6)/16;
 
248
-sech(x)^5*(sinh(x)^5+2*(sinh(x)^4+6*cosh(x)^2*sinh(x)^2+cosh(x)^4)-13*(sinh(x)^3+3*cosh(x)^2*sinh(x))+10*cosh(x)^2*sinh(x)^3-8*(sinh(x)^2+cosh(x)^2)+5*cosh(x)^4*sinh(x)+34*sinh(x)+6)/16$
 
249
trigsimp(%);
 
250
-(sinh(x)^5+sinh(x)^4-2*sinh(x)^3)/cosh(x)^5$
 
251
 
 
252
cos(x)*(sec(x)^2*tan(x)+1)-sec(x)^2*sin(x)-cos(x);
 
253
cos(x)*(sec(x)^2*tan(x)+1)-sec(x)^2*sin(x)-cos(x)$
 
254
trigsimp(%);
 
255
0$
 
256
 
 
257
v*cos(x)*sec(x)^2*tan(x)+(-v*sec(x)^2-2*'diff(v,x))*sin(x)+'diff(v,x)*cos(x)*sec(x)+'diff(v,x,2)*cos(x);
 
258
v*cos(x)*sec(x)^2*tan(x)+(-v*sec(x)^2-2*'diff(v,x))*sin(x)+'diff(v,x)*cos(x)*sec(x)+'diff(v,x,2)*cos(x)$
 
259
trigsimp(%);
 
260
-2*'diff(v,x,1)*sin(x)+'diff(v,x,2)*cos(x)+'diff(v,x,1)$
 
261