Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

could setParameter work with struct #146

Closed
pbpf opened this issue Sep 25, 2019 · 2 comments
Closed

could setParameter work with struct #146

pbpf opened this issue Sep 25, 2019 · 2 comments

Comments

@pbpf
Copy link

pbpf commented Sep 25, 2019

Think about there are many parameters, so that it will be too bad to add them one by one. So I trying to do something like this


earth.R0=6378137;
earth.g0=9.8;
p.earth=earth;
p.x0=1;
solver.setParameter('p' , p);

and in varsfun


sh.addParameter('p');

Then in odefun
I want to get it back.

@jkoendev
Copy link
Member

jkoendev commented Sep 29, 2019

If your parameters are just constant values then it is better not to use parameters but pass the values using anonymous functions. Parameters are also optimization variables that you can set bounds on them, so they are not efficient for constants.

You can see how to do it in this example:
https://github.com/OpenOCL/OpenOCL/blob/master/%2Bocl/%2Bexamples/ballandbeam.m

All the constants are stored in a struct conf. You can pass a anonymous function to the solver like (for the system synamics):

@(dh,x,z,u,p) odefun(dh,x,z,u,p,conf);

and so odefun has conf as an input.

function odefun(dh, x, z, u, p, conf)
  ...
end

If you are unfamiliar with anonymous functions, i can try to explain in more detail!

You can also use the parameters but it will be not efficient. And you can not use struct, but add them one by one:

sh.addParameter('p')
sh.addParameter('R0')
etc.

@jkoendev
Copy link
Member

note that we introduced the userdata field to pass constant parameters/values/structs..

See:
https://github.com/OpenOCL/OpenOCL/blob/v7.03/%2Bocl/%2Bexamples/ballandbeam.m

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

No branches or pull requests

2 participants