Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've got the following matlab code:

  eta1=0.7;
  omega=10;
  f = @(t) eta1*sin(omega*t) + (1-eta1)*sin(2*omega*t)
I can call

  f(2)
and return a scaler value. I could just make a function in a separate document, but then I would have to pass in my parameters eta1 and omega. By using a closure, I just have to set those parameters in my code beforehand. Also, if I want to change my forcing term, by adding new parameters, I don't have to change the function definition, I just add those parameters right in.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: