| 1 |
\NeedsTeXFormat{LaTeX2e} |
| 2 |
\ProvidesPackage{fp-eqn}[1995/04/03] |
| 3 |
|
| 4 |
%version information |
| 5 |
\def\FP@eqnversion{0.4} |
| 6 |
\message{% |
| 7 |
`Fixed Point Equation Solver',% |
| 8 |
\space\space\space% |
| 9 |
Version \FP@eqnversion\space% |
| 10 |
\space(C) Michael Mehlich% |
| 11 |
\space\space\space\space\space\space\space% |
| 12 |
\space\space\space\space\space\space\space% |
| 13 |
} |
| 14 |
|
| 15 |
%resolve dependencies |
| 16 |
\RequirePackage{fp} |
| 17 |
|
| 18 |
%%%public area (macros which may be used)%%% |
| 19 |
|
| 20 |
\def\FPlsolve#1#2#3{\FP@lsolve#1{#2}{#3}} % #1 := x with #2*x+#3=0 |
| 21 |
\def\FPqsolve#1#2#3#4#5{\FP@qsolve#1#2{#3}{#4}{#5}} % #1,#2 := x with #3*x^2+#4*x+#5 = 0 |
| 22 |
\def\FPcsolve#1#2#3#4#5#6#7{\FP@csolve#1#2#3{#4}{#5}{#6}{#7}} |
| 23 |
% #1,#2,#3 := x with #4*x^3+#5*x^2+#6*x+#7 = 0 |
| 24 |
\def\FPqqsolve#1#2#3#4#5#6#7#8#9{\FP@qqsolve#1#2#3#4{#5}{#6}{#7}{#8}{#9}} |
| 25 |
% #1,#2,#3,#4 := x with #5*x^4+#6*x^3+#7*x^2+#8*x+#9 = 0 |
| 26 |
|
| 27 |
%%%private fp-area (don't use these macros)%%% |
| 28 |
|
| 29 |
%compute the solution of a*x + b = 0 |
| 30 |
\def\FP@lsolve@warn#1{% |
| 31 |
%value determining warning |
| 32 |
\FPifzero{#1}% |
| 33 |
\FP@warnmessage{Linear equation has infinitely many solutions, choosing 0}% |
| 34 |
\edef\FP@tmp{0}% |
| 35 |
\else% |
| 36 |
\FP@errmessage{Linear equation does not have a solution}% |
| 37 |
\fi% |
| 38 |
} |
| 39 |
|
| 40 |
\def\FP@@lsolve#1#2{% |
| 41 |
\FPdiv\FP@tmp{#2}{#1}% |
| 42 |
\FPneg\FP@tmp\FP@tmp% |
| 43 |
} |
| 44 |
|
| 45 |
\def\FP@lsolve#1#2#3{% |
| 46 |
% #1 macro, which gets the result |
| 47 |
% #2 value a |
| 48 |
% #3 value b |
| 49 |
% |
| 50 |
\FP@beginmessage{LSOLVE}% |
| 51 |
% |
| 52 |
{\def\FP@beginmessage##1{}% |
| 53 |
\def\FP@endmessage##1{}% |
| 54 |
% |
| 55 |
\FPifzero{#2}% |
| 56 |
\FP@lsolve@warn{#3}% |
| 57 |
\else% |
| 58 |
\FP@@lsolve{#2}{#3}% |
| 59 |
\fi% |
| 60 |
% |
| 61 |
\global\let\FP@tmp\FP@tmp% |
| 62 |
}% |
| 63 |
% |
| 64 |
\let#1\FP@tmp% |
| 65 |
% |
| 66 |
\FP@endmessage{}% |
| 67 |
} |
| 68 |
|
| 69 |
%compute the solutions of a*x^2 + b*x + c = 0 |
| 70 |
\def\FP@@qsolve#1#2#3{% |
| 71 |
% \FP@tmpc := 2*a |
| 72 |
\FPadd\FP@tmpc{#1}{#1}% |
| 73 |
% |
| 74 |
% \FP@tmpb := b*b |
| 75 |
\FPmul\FP@tmpd{#2}{#2}% |
| 76 |
% |
| 77 |
% \FP@tmpc := 4*a*c |
| 78 |
\FPmul\FP@tmpe\FP@tmpc{#3}% |
| 79 |
\FPadd\FP@tmpe\FP@tmpe\FP@tmpe% |
| 80 |
% |
| 81 |
% \FP@tmpf := b^2 - 4*a*c |
| 82 |
\FPsub\FP@tmpf\FP@tmpd\FP@tmpe% |
| 83 |
% |
| 84 |
\FPifneg\FP@tmpf% |
| 85 |
\FP@errmessage{Quadratic equation does not have a solution}% |
| 86 |
\else% |
| 87 |
% \FP@tmpd := sqrt(b^2 - 4*a*c) |
| 88 |
\FProot\FP@tmpd\FP@tmpf{2}% |
| 89 |
% |
| 90 |
% solution 1: x = (-b + sqrt(b^2 - 4*a*c))/(2*a) |
| 91 |
\FPsub\FP@tmp\FP@tmpd{#2}% |
| 92 |
\FPdiv\FP@tmpe\FP@tmp\FP@tmpc% |
| 93 |
% |
| 94 |
% solution 2: x = (-b + sqrt(b^2 - 4*a*c))/(2*a) |
| 95 |
\FPadd\FP@tmp\FP@tmpd{#2}% |
| 96 |
\FPdiv\FP@tmpd\FP@tmp\FP@tmpc% |
| 97 |
\FPneg\FP@tmpd\FP@tmpd% |
| 98 |
\fi% |
| 99 |
} |
| 100 |
|
| 101 |
\def\FP@qsolve#1#2#3#4#5{% |
| 102 |
% #1 macro, which gets the 1st result |
| 103 |
% #2 macro, which gets the 2nd result |
| 104 |
% #3 value a |
| 105 |
% #4 value b |
| 106 |
% #5 value c |
| 107 |
% |
| 108 |
\FP@beginmessage{QSOLVE}% |
| 109 |
% |
| 110 |
{\def\FP@beginmessage##1{}% |
| 111 |
\def\FP@endmessage##1{}% |
| 112 |
% |
| 113 |
\FPifzero{#3}% |
| 114 |
\FP@warnmessage{Quadratic equation is linear}% |
| 115 |
\FP@lsolve\FP@tmpe{#4}{#5}% |
| 116 |
\let\FP@tmpd\FP@tmpe% |
| 117 |
\else% |
| 118 |
\FP@@qsolve{#3}{#4}{#5}% |
| 119 |
\fi% |
| 120 |
% |
| 121 |
\global\let\FP@tmpa\FP@tmpe% |
| 122 |
\global\let\FP@tmpb\FP@tmpd% |
| 123 |
}% |
| 124 |
% |
| 125 |
\let#1\FP@tmpa% |
| 126 |
\let#2\FP@tmpb% |
| 127 |
% |
| 128 |
\FP@endmessage{}% |
| 129 |
} |
| 130 |
|
| 131 |
%compute the solutions of a*x^3 + b*x^2 + c*x + d = 0 |
| 132 |
\def\FP@@csolve#1#2#3#4{% |
| 133 |
%reducation of cubic equation |
| 134 |
%\FPeval\FP@tmpp{(#3)/(3*(#1)) - mul(copy((#2)/(3*(#1))))}% |
| 135 |
\FPupn\FP@tmpp{#3 3 #1 mul div #2 3 #1 mul div copy mul sub}% |
| 136 |
%\FPeval\FP@tmpq{mul(mul(copy(copy((#2)/(3*(#1)))))) - (#2)*(#3)/(6*(#1)*(#1)) + (#4)/(2*(#1))}% |
| 137 |
\FPupn\FP@tmpq{#2 3 #1 mul div copy copy mul mul #2 #3 mul 6 #1 mul #1 mul div sub #4 2 #1 mul div add}% |
| 138 |
% |
| 139 |
%check whether solution is trivial |
| 140 |
\FPifzero\FP@tmpp% |
| 141 |
%\FPeval\FP@tmpf{root(3,abs(2*\FP@tmpq)) * sgn(\FP@tmpq)}% |
| 142 |
\FPupn\FP@tmpf{3 2 \FP@tmpq{} mul abs root \FP@tmpq{} sgn mul}% |
| 143 |
\let\FP@tmpe\FP@tmpf% |
| 144 |
\let\FP@tmpd\FP@tmpf% |
| 145 |
\else% |
| 146 |
%compute D |
| 147 |
%\FPeval\FP@tmpD{mul(copy(\FP@tmpq)) + mul(mul(copy(copy(\FP@tmpp))))}% |
| 148 |
\FPupn\FP@tmpD{\FP@tmpq{} copy mul \FP@tmpp{} copy copy mul mul add}% |
| 149 |
\FPsgn\FP@tmp\FP@tmpD% |
| 150 |
\expandafter\ifnum\FP@tmp=1\relax% |
| 151 |
%only one real valued solution, compute it |
| 152 |
\FProot\FP@tmpD\FP@tmpD{2}% |
| 153 |
\FPsub\FP@tmpf\FP@tmpD\FP@tmpq% |
| 154 |
\FPadd\FP@tmpe\FP@tmpD\FP@tmpq% |
| 155 |
\FPneg\FP@tmpe\FP@tmpe% |
| 156 |
%\FPeval\FP@tmpf{root(3,abs(\FP@tmpf)) * sgn(\FP@tmpf) + root(3,abs(\FP@tmpe)) * sgn(\FP@tmpe)}% |
| 157 |
\FPupn\FP@tmpf{3 \FP@tmpf{} abs root \FP@tmpf{} sgn mul 3 \FP@tmpe{} abs root \FP@tmpe{} sgn mul add}% |
| 158 |
\FP@warnmessage{Cubic equation has only one real valued solution}% |
| 159 |
\let\FP@tmpe\FP@tmpf% |
| 160 |
\let\FP@tmpd\FP@tmpf% |
| 161 |
\else% |
| 162 |
%compute r and phi/3 |
| 163 |
%\FPeval\FP@tmpr{root(2,abs(\FP@tmpp)) * sgn(\FP@tmpq) * 2}% |
| 164 |
\FPupn\FP@tmpr{2 \FP@tmpp{} abs root \FP@tmpq{} sgn mul}% |
| 165 |
%\FPeval\FP@tmpp{arccos(\FP@tmpq/\FP@tmpr/\FP@tmpr/\FP@tmpr)/3}% |
| 166 |
\FPupn\FP@tmpp{\FP@tmpq{} \FP@tmpr{} div \FP@tmpr{} div \FP@tmpr{} div arccos 3 div}% |
| 167 |
%compute the three solutions |
| 168 |
\FPmul\FP@tmpr{2}\FP@tmpr% |
| 169 |
\FPeval\FP@tmpf{neg(\FP@tmpr) * cos(\FP@tmpp)}% |
| 170 |
\FPeval\FP@tmpe{(\FP@tmpr) * cos(1.047197551196597746-(\FP@tmpp))}% |
| 171 |
\FPeval\FP@tmpd{(\FP@tmpr) * cos(1.047197551196597746+(\FP@tmpp))}% |
| 172 |
\fi% |
| 173 |
\fi% |
| 174 |
% |
| 175 |
\FPeval\FP@tmpf{(\FP@tmpf)-(#2)/(3*(#1))}% |
| 176 |
\FPeval\FP@tmpe{(\FP@tmpe)-(#2)/(3*(#1))}% |
| 177 |
\FPeval\FP@tmpd{(\FP@tmpd)-(#2)/(3*(#1))}% |
| 178 |
} |
| 179 |
|
| 180 |
\def\FP@csolve#1#2#3#4#5#6#7{% |
| 181 |
% #1 macro, which gets the 1st result |
| 182 |
% #2 macro, which gets the 2nd result |
| 183 |
% #3 macro, which gets the 3nd result |
| 184 |
% #4 value a |
| 185 |
% #5 value b |
| 186 |
% #6 value c |
| 187 |
% #7 value d |
| 188 |
% |
| 189 |
\FP@beginmessage{CSOLVE}% |
| 190 |
% |
| 191 |
{\def\FP@beginmessage##1{}% |
| 192 |
\def\FP@endmessage##1{}% |
| 193 |
% |
| 194 |
\FPifzero{#4}% |
| 195 |
\FP@warnmessage{Cubic equation is quadratic}% |
| 196 |
\FP@qsolve\FP@tmpe\FP@tmpf{#5}{#6}{#7}% |
| 197 |
\let\FP@tmpd\FP@tmpe% |
| 198 |
\else% |
| 199 |
\FP@@csolve{#4}{#5}{#6}{#7}% |
| 200 |
\fi% |
| 201 |
% |
| 202 |
\global\let\FP@tmpa\FP@tmpf% |
| 203 |
\global\let\FP@tmpb\FP@tmpe% |
| 204 |
\global\let\FP@tmpc\FP@tmpd% |
| 205 |
}% |
| 206 |
% |
| 207 |
\let#1\FP@tmpa% |
| 208 |
\let#2\FP@tmpb% |
| 209 |
\let#3\FP@tmpc% |
| 210 |
% |
| 211 |
\FP@endmessage{}% |
| 212 |
} |
| 213 |
|
| 214 |
%compute the solutions of a*x^4 + b*x^3 + c*x^2 + d*x + e = 0 |
| 215 |
\def\FP@qqsolveAy#1#2#3{% |
| 216 |
\FPeval\FP@tmpA{8*(\FP@tmpyc)+((#2)*(#2)/(#1)-4*(#3))/(#1)}% |
| 217 |
\FPsgn\FP@tmp\FP@tmpA% |
| 218 |
\expandafter\ifnum\FP@tmp>0\relax% |
| 219 |
\let\FP@tmpy\FP@tmpyc% |
| 220 |
\else% |
| 221 |
\FPeval\FP@tmpA{8*(\FP@tmpyb)+((#2)*(#2)/(#1)-4*(#3))/(#1)}% |
| 222 |
\FPsgn\FP@tmp\FP@tmpA% |
| 223 |
\expandafter\ifnum\FP@tmp>0\relax% |
| 224 |
\let\FP@tmpy\FP@tmpyb% |
| 225 |
\else% |
| 226 |
\FPeval\FP@tmpA{8*(\FP@tmpya)+((#2)*(#2)/(#1)-4*(#3))/(#1)}% |
| 227 |
\FPsgn\FP@tmp\FP@tmpA% |
| 228 |
\expandafter\ifnum\FP@tmp>0\relax% |
| 229 |
\let\FP@tmpy\FP@tmpya% |
| 230 |
\else% |
| 231 |
\FP@errmessage{Equation of 4-th degree has no solution}% |
| 232 |
\fi% |
| 233 |
\fi% |
| 234 |
\fi% |
| 235 |
\FProot\FP@tmpA\FP@tmpA{2}% |
| 236 |
} |
| 237 |
|
| 238 |
\def\FP@@qqsolve#1#2#3#4#5{% |
| 239 |
%compute cubic equation |
| 240 |
\FPeval\FP@tmpyb{neg(4*(#3)/(#1))}% |
| 241 |
\FPeval\FP@tmpyc{2*(#2)*(#4)/(#1)/(#1) - 8*(#5)/(#1)}% |
| 242 |
\FPeval\FP@tmpyd{(#5)/(#1)*(4*(#3)/(#1) - (#2)*(#2)/(#1)/(#1)) - (#4)*(#4)/(#1)/(#1)}% |
| 243 |
%solve cubic equation |
| 244 |
\FP@@csolve{8}\FP@tmpyb\FP@tmpyc\FP@tmpyd% |
| 245 |
%hold an arbitrary solution |
| 246 |
\let\FP@tmpya\FP@tmpd% |
| 247 |
\let\FP@tmpyb\FP@tmpe% |
| 248 |
\let\FP@tmpyc\FP@tmpf% |
| 249 |
%compute A and y from these solutions |
| 250 |
\FP@qqsolveAy{#1}{#2}{#3}% |
| 251 |
%compute first quadratic equation |
| 252 |
\FPeval\FP@tmpp{((#2)/(#1)+(\FP@tmpA))/2}% |
| 253 |
\FPeval\FP@tmpq{(\FP@tmpy)+((#2)*(\FP@tmpy)-(#4))/(#1)/(\FP@tmpA)}% |
| 254 |
\FP@qsolve\FP@tmpg\FP@tmpf{1}\FP@tmpp\FP@tmpq% |
| 255 |
%compute second quadratic equation |
| 256 |
\FPeval\FP@tmpp{((#2)/(#1)-(\FP@tmpA))/2}% |
| 257 |
\FPeval\FP@tmpq{(\FP@tmpy)-((#2)*(\FP@tmpy)-(#4))/(#1)/(\FP@tmpA)}% |
| 258 |
\FP@qsolve\FP@tmpe\FP@tmpd{1}\FP@tmpp\FP@tmpq% |
| 259 |
} |
| 260 |
|
| 261 |
%subsolve a*x^4 + c*x^2 + e = 0 |
| 262 |
\def\FP@qsolve@zero#1#2#3{% |
| 263 |
\FPeval\FP@tmpy{(#2)*(#2) - 4*(#1)*(#3)}% |
| 264 |
\FPsgn\FP@tmp\FP@tmpy% |
| 265 |
\expandafter\ifnum\FP@tmp<0\relax% |
| 266 |
\FP@errmessage{Equation of 4-th degree has no solution}% |
| 267 |
\else% |
| 268 |
%compute solutions |
| 269 |
\FPeval\FP@tmpya{neg(root(2,\FP@tmpy)+(#2))/(2*(#1))}% |
| 270 |
\FPeval\FP@tmpyb{(root(2,\FP@tmpy)-(#2))/(2*(#1))}% |
| 271 |
\FPsgn\FP@tmpf\FP@tmpya% |
| 272 |
\FPsgn\FP@tmpg\FP@tmpyb% |
| 273 |
\ifnum\expandafter\ifnum\FP@tmpf<0 0\else1\fi\expandafter\ifnum\FP@tmpg<0 0\else1\fi=0\relax% |
| 274 |
\FP@errmessage{Equation of 4-th degree has no solution}% |
| 275 |
\else% |
| 276 |
\expandafter\ifnum\FP@tmpf<0\relax% |
| 277 |
\FP@warnmessage{Equation of 4-th degree only has two solutions}% |
| 278 |
\let\FP@tmpya\FP@tmpyb% |
| 279 |
\else% |
| 280 |
\expandafter\ifnum\FP@tmpg<0\relax% |
| 281 |
\FP@warnmessage{Equation of 4-th degree only has two solutions}% |
| 282 |
\let\FP@tmpyb\FP@tmpya% |
| 283 |
\fi% |
| 284 |
\fi% |
| 285 |
%compute solutions |
| 286 |
\FProot\FP@tmpg\FP@tmpya{2}% |
| 287 |
\FPneg\FP@tmpf\FP@tmpg% |
| 288 |
\FProot\FP@tmpe\FP@tmpyb{2}% |
| 289 |
\FPneg\FP@tmpd\FP@tmpe% |
| 290 |
\fi% |
| 291 |
\fi% |
| 292 |
} |
| 293 |
|
| 294 |
%subsolve a*x^4 + b*x^3 + c*x^2 + b*x + a = 0 |
| 295 |
\def\FP@qsolve@eq#1#2#3{% |
| 296 |
\FPeval\FP@tmpy{(#2)*(#2) - 4*(#1)*(#3) + 8*(#1)*(#1)}% |
| 297 |
\FPsgn\FP@tmp\FP@tmpy% |
| 298 |
\expandafter\ifnum\FP@tmp<0\relax% |
| 299 |
\FP@errmessage{Equation of 4-th degree has no solution}% |
| 300 |
\else% |
| 301 |
%compute solutions |
| 302 |
\FPeval\FP@tmpya{neg(root(2,\FP@tmpy)+(#2))/(2*(#1))}% |
| 303 |
\FPeval\FP@tmpyb{(root(2,\FP@tmpy)-(#2))/(2*(#1))}% |
| 304 |
\FPeval\FP@tmpyc{(\FP@tmpya)*(\FP@tmpya)-4}% |
| 305 |
\FPeval\FP@tmpyd{(\FP@tmpyb)*(\FP@tmpyb)-4}% |
| 306 |
\FPsgn\FP@tmpf\FP@tmpyc% |
| 307 |
\FPsgn\FP@tmpg\FP@tmpyd% |
| 308 |
\ifnum\expandafter\ifnum\FP@tmpf<0 0\else1\fi\expandafter\ifnum\FP@tmpg<0 0\else1\fi=0\relax% |
| 309 |
\FP@errmessage{Equation of 4-th degree has no solution}% |
| 310 |
\else% |
| 311 |
\expandafter\ifnum\FP@tmpf<0\relax% |
| 312 |
\FP@warnmessage{Equation of 4-th degree only has two solutions}% |
| 313 |
\let\FP@tmpya\FP@tmpyb% |
| 314 |
\let\FP@tmpyc\FP@tmpyd% |
| 315 |
\else% |
| 316 |
\expandafter\ifnum\FP@tmpg<0\relax% |
| 317 |
\FP@warnmessage{Equation of 4-th degree only has two solutions}% |
| 318 |
\let\FP@tmpyb\FP@tmpya% |
| 319 |
\let\FP@tmpyd\FP@tmpyc% |
| 320 |
\fi% |
| 321 |
\fi% |
| 322 |
%compute solutions |
| 323 |
\FPeval\FP@tmpg{((\FP@tmpya)+root(2,(\FP@tmpyc)))/2}% |
| 324 |
\FPeval\FP@tmpf{((\FP@tmpya)-root(2,(\FP@tmpyc)))/2}% |
| 325 |
\FPeval\FP@tmpe{((\FP@tmpyb)+root(2,(\FP@tmpyd)))/2}% |
| 326 |
\FPeval\FP@tmpd{((\FP@tmpyb)-root(2,(\FP@tmpyd)))/2}% |
| 327 |
\fi% |
| 328 |
\fi% |
| 329 |
} |
| 330 |
|
| 331 |
%complete solve of equation of 4-th degree |
| 332 |
\def\FP@qqsolve#1#2#3#4#5#6#7#8#9{% |
| 333 |
% #1 macro, which gets the 1st result |
| 334 |
% #2 macro, which gets the 2nd result |
| 335 |
% #3 macro, which gets the 3nd result |
| 336 |
% #4 macro, which gets the 4th result |
| 337 |
% #5 value a |
| 338 |
% #6 value b |
| 339 |
% #7 value c |
| 340 |
% #8 value d |
| 341 |
% #9 value e |
| 342 |
% |
| 343 |
\FP@beginmessage{QQSOLVE}% |
| 344 |
% |
| 345 |
{\def\FP@beginmessage##1{}% |
| 346 |
\def\FP@endmessage##1{}% |
| 347 |
% |
| 348 |
\FPifzero{#5}% |
| 349 |
\FP@warnmessage{Equation of 4-th degree is cubic}% |
| 350 |
\FP@csolve\FP@tmpd\FP@tmpe\FP@tmpf{#6}{#7}{#8}{#9}% |
| 351 |
\let\FP@tmpg\FP@tmpd% |
| 352 |
\else% |
| 353 |
\FPsgn\FP@tmpg{#6}% |
| 354 |
\FPsgn\FP@tmpf{#8}% |
| 355 |
\ifnum\expandafter\ifnum\FP@tmpg=0 0\else1\fi\expandafter\ifnum\FP@tmpf=0 0\else1\fi=0\relax% |
| 356 |
%case b=d=0 |
| 357 |
\FP@qsolve@zero{#5}{#7}{#9}% |
| 358 |
\else% |
| 359 |
\FPupn\FP@tmpg{#5 #9 sub sgn}% |
| 360 |
\FPupn\FP@tmpf{#6 #8 sub sgn}% |
| 361 |
\ifnum\expandafter\ifnum\FP@tmpg=0 0\else1\fi\expandafter\ifnum\FP@tmpf=0 0\else1\fi=0\relax% |
| 362 |
%case a=e, b=d |
| 363 |
\FP@qsolve@eq{#5}{#6}{#7}% |
| 364 |
\else% |
| 365 |
\FP@@qqsolve{#5}{#6}{#7}{#8}{#9}% |
| 366 |
\fi% |
| 367 |
\fi% |
| 368 |
\fi% |
| 369 |
% |
| 370 |
\global\let\FP@tmpa\FP@tmpg% |
| 371 |
\global\let\FP@tmpb\FP@tmpf% |
| 372 |
\global\let\FP@tmpc\FP@tmpe% |
| 373 |
\global\let\FP@tmpd\FP@tmpd% |
| 374 |
}% |
| 375 |
% |
| 376 |
\let#1\FP@tmpa% |
| 377 |
\let#2\FP@tmpb% |
| 378 |
\let#3\FP@tmpc% |
| 379 |
\let#4\FP@tmpd% |
| 380 |
% |
| 381 |
\FP@endmessage{}% |
| 382 |
} |