I want to solve some iteration in chemical engineering problem using matlab. So the problem that I want to solve is Calculating the inter convertion of series adiabatic reactors, here is the algorithm given:
I have been solved it in VBA Excel and the code is:
Public Function intrap(h, y)
n = y.Count
If n Mod 2 > 0 Then
MsgBox ("JUMLAH DATA HARUS GENAP")
intrap = "ERROR:JUMLAH DATA HARUS GENAP"
Exit Function
End If
For i = 1 To n
s1 = s1 + y(i)
Next i
For i = 2 To (n - 1)
s2 = s2 + y(i)
Next i
intrap = (h / 2) * (y(1) + (2 * s2) + y(n))
End Function
and the output is Output
So, how to do it in matlab?