Subscribed unsubscribe Subscribe Subscribe

TI-Nspire / 微積分 / 臺形積分

TI-Nspire + 微積分

.lua

-- Trapezoidal Integration
SUM = 1     -- initial value
data = {    -- f(x) = e^x, x = from 0 to 2, dx = 0.1
1,
1.105170918,
1.221402758,
1.349858808,
1.491824698,
1.648721271,
1.8221188,
2.013752707,
2.225540928,
2.459603111,
2.718281828,
3.004166024,
3.320116923,
3.669296668,
4.055199967,
4.48168907,
4.953032424,
5.473947392,
6.049647464,
6.685894442,
7.389056099,
}

function integral(sum, old, new, dt)
   if old == nil then 
      return sum
   else
      return sum + (old + new) * dt / 2
   end
end

for i = 1, #data do
   SUM = integral(SUM, data[i-1], data[i], 0.1)
end
print(SUM)

 

f:id:ti-nspire:20161218164243p:plain:h500
 

  • Reference:

Excelでわかる数学の基礎

Excelでわかる数学の基礎

p.93

Remove all ads