I have code generated by AI Aria in Opera browser
The code gives wrong answer only for: Depreciation factor=1?
assetValue=10000; salvageValue=2000; assetLife=5; depreciationFactor=1; decliningBalanceDepreciation[assetValue_, salvageValue_, assetLife_, depreciationFactor_] := Module[{bookValue = assetValue, depTable = {}}, AppendTo[ depTable, {"Year", "Beginning Book Value", "Depreciation Percent", "Depreciation Amount", "Accumulated Depreciation", "Ending Book Value"}]; Do[depreciation = Min[bookValue - salvageValue, depreciationFactor*bookValue/assetLife]; accumulatedDepreciation = If[i == 1, depreciation, Last[depTable][[5]] + depreciation]; endingBookValue = Max[salvageValue, bookValue - depreciation]; AppendTo[ depTable, {i, bookValue, (depreciation/bookValue)*100, depreciation, accumulatedDepreciation, endingBookValue}]; bookValue = endingBookValue;, {i, 1, assetLife}]; depTable] Grid[decliningBalanceDepreciation[assetValue, salvageValue, assetLife, depreciationFactor], Frame -> All] //N See below:
I use this Calculator to compute values.
Where is the mistake in the code?
Thanks.


depreciation = If[i == assetLife, bookValue - salvageValue, Min[bookValue - salvageValue, depreciationFactor*bookValue/assetLife]]gives the expected result for the last record in the table {{4096., 51.1719, 2096., 8000., 2000.}} $\endgroup$819.20for 5th year as in original code. So which calculator is correct now? $\endgroup$