I want to translate a script in VBA to Matlab.
Here's the original script in VBA:
Function tau(h, b, override)nMax = 60mMax = 60If (override = 0) Thenh = 2 * htau = 0 For n = -nMax To nMax For m = -mMax To mMax If (n = 0) And (m = 0) Then Else tau = tau + (-1) ^ (n + m) * 1 / (n * n + (m * h / b) * (m * h / b)) ^ (1.5) End If Next Nexttau = tau * 0.5 * (h / b / 3.14159265358979) ^ 1.5Elsetau = overrideEnd IfEnd Function
This script returns tau as -0.242648
My Matlab equivalent returns 0.085214. Here's the script:
function tau = FindTau(h,b,nMax,mMax) h = 2*h; tau = 0; for n = -nMax:nMax for m = -mMax:mMax if n ~= 0 && m ~= 0 tau = tau + (-1) ^ (n + m) * 1 / (n * n + (m * h / b) * (m * h / b)) ^ (1.5); end end end tau = tau * 0.5 * (h / b / 3.14159265358979) ^ 1.5;end
I don't understand what I'm doing wrong. For nMax = mMax = 60, h = 3.048, and b = 5.4864, I am getting two different results with the same math from two different languages. Any help would be greatly appreciated.
Thanks, Kat
Best Answer