Replies: 5 comments
-
Your example above is somewhat incomplete. I assume you are creating an ADFun object corresponding to get_p(x) and then evaluating it. If so, using the test2 definition, you will always get the value of x during the creation of the ADFun object because you have converted x from a variable to a constant parameter; see |
Beta Was this translation helpful? Give feedback.
-
Yes, your assume is right. In fact, the parameter 'pos_x' of function 'get_p' is a variable when optimizing, but I can not get the right result with following code. So is there any problem in the following code? Is the problem in the comparison ' (pos_x > _threshold)'?
|
Beta Was this translation helpful? Give feedback.
-
Here is more code.
|
Beta Was this translation helpful? Give feedback.
-
This is because comparison operations have a I think what you want is a conditional expression; see |
Beta Was this translation helpful? Give feedback.
-
Wow, wonderful, the conditional expression is work. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
I define a function like this. I have ensured the pos_x is right from 0.0 to 10.0. But the output is always 0.0, seen that the comparison do not work.
So I tested the output of 'AD pos_x'. test1 can output the right data from 0.0 to 10.0, but test2 output the wrong data with always 0.0.
test1
test2
So can you provide any suggestion please, thanks a lot.
Beta Was this translation helpful? Give feedback.
All reactions