Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrap function #8

Closed
ChrisRackauckas opened this issue Oct 20, 2017 · 0 comments
Closed

Unwrap function #8

ChrisRackauckas opened this issue Oct 20, 2017 · 0 comments

Comments

@ChrisRackauckas
Copy link
Member

After #7 we can do @unwrap_function on a function definition is:

@unwrap_function (u,nothing) function f(t,u)
  # code
end

gives

function f(t,u)
  @unwrap u
  # code
  @wrap u
end

so that way using the values by their names as variables "just works" in the function. (u,nothing) means to unwrap u without changing the variable names. (du,:d_) would mean to unwrap like d_a, d_b, d_c, etc. Example:

@unwrap_function (u,nothing) (du,:d_) function f(t,u,du)
  d_a = a*c
  d_b = b*c
  d_c = a*b + c
end

would be the same as

@unwrap_function (u,nothing) (du,:d_) function f(t,u,du)
  du[1] = u[1]*u[3]
  du[2] = u[2]*u[3]
  du[3] = u[1]*u[2] + u[3]
end

which is clearly a nicer way to write the diffeq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant