Polynomial derivative: Difference between revisions

m
Line 615:
</pre>
===Classical programming===
Assuming we ignore the existence of the <code>∂</code> operator, here is a typical RPL program that handles polynoms as arrayslists of scalars, asto requiredbe completed by another program to display the tasklist on a fancier way.
≪ → scalarscoeffs
scalarsIF coeffs SIZE 1 - { }
IFTHEN SWAP
THEN { } 1 LAST FOR j
LAST 2 SWAP FORcoeffs j 1 + GET j 1 MAX * +
scalars j GET j 1 - * +
NEXT
ELSE { 0 +}
END
≫ ≫
'DPDX' STO
 
[{5]} DPDX
[{4 -3]} DPDX
[{-1 6 5]} DPDX
[{-4 3 -2 1]} DPDX
[{1 1 0 -1 -1]} DPDX
{{out}}
<pre>
5: [{ 0 ]}
4: [{ -3 ]}
3: [{ 6 10 ]}
2: [{ 3 -4 3 ]}
1: [{ 1 0 -3 -4 ]}
</pre>
=== Fancy output ===
≪ → coeffs
≪ coeffs 1 GET
coeffs SIZE 2 FOR j
scalarscoeffs j GET ‘x’ j 1 - ^ * SWAP +
-1 STEP
≫ COLCT
‘→EQ’ STO
 
{1 1 0 -1 -1} DPDX
DUP →EQ
{{out}}
<pre>
2: { 1 0 -3 -4 }
1: '1-3*x^2-4*x^3'
</pre>
 
1,150

edits