Page 1 of 1

PiecewiseLinearFunction in MatLab

Posted: Wed Dec 21, 2016 1:44 am
by steidlr
Hello, again me, and again with a similar issue,

i want to create a linear function for the force in MatLab - the c++ code looks so:

Code: Select all

PiecewiseLinearFunction *forceX = new PiecewiseLinearFunction(2, time, fXofT);
In MatLab i can acces to the constructor like:
Force = PieceWiseLinearFunction();
but how can i add the parameters time and fXofT in MatLab??

Re: PiecewiseLinearFunction in MatLab

Posted: Wed Dec 21, 2016 2:32 am
by tkuchida
Have you tried addPoint()? There's a C++ example that uses addPoint() here: https://github.com/opensim-org/opensim- ... e.cpp#L212; here's the documentation: https://simtk.org/api_docs/opensim/api_ ... ction.html.

Re: PiecewiseLinearFunction in MatLab

Posted: Wed Dec 21, 2016 4:53 am
by steidlr
Thank you,

thats a good point - for my understanding, if I have the timepoints at 0 and 2 and the corresponding force at 0 and 15 my code should look like:

Code: Select all

Force = PiecewiseLinearFunction();
Force.addPoint(0, 0);
Force.addPoint(2, 15);
Am I right?

Re: PiecewiseLinearFunction in MatLab

Posted: Thu Dec 22, 2016 10:39 pm
by tkuchida
Yes, that code looks correct. I recommend getting into the habit of running tests using simple models and verifying that the answers are what you expect before trying to tackle more complex problems.