Limit angl​e in [-90,​90] degree

34 次查看(过去 30 天)
warnerchang
warnerchang 2022-5-2
As I was using ode45 to solve ODEs, I do not know to limit the result in [-90,90] degree. Anyone may provide some help?
  3 个评论
Walter Roberson
Walter Roberson 2022-5-2
What should happen if the angle would go outside that range?
Star Strider
Star Strider 2022-5-3
I have no idea what the code is, however using 90 times the tanh function could be one way of limiting the angle. This has the advatage of being differentiable rather than using a stepwise limit that would not be differentiable.

请先登录,再进行评论。

采纳的回答

John D'Errico
John D'Errico 2022-5-2
编辑:John D'Errico 2022-5-2
You cannot simply constrain an ODE solver to stay within bounds. However, almost certainly, if the ODE solver wants to go outside of those bounds, allow it to do so, because that does not cause a problem. just take the output and then deal with it as a post-processing step.
That is, if X is a vector that ODE45 returns, then use this line of code to remap the predictions back into the [-90,90) interval:
X = mod(X,180) - 90;
For example, that remaps a result that was 91 degrees into -89 degrees. (Note that mod works, even if X is not an integer.)
It would be my guess that this parameter is effectively measuring the slope of a line, in degrees. (It is about the only common reason I can see why you wish to constrain the parameter to lie in that interval.)
And we could argue that the slope of a line must always be between -90 and +90 degrees. But if we had a line with a slope that was predicted to be outside of that interval, then the computation I have provided returns a new slope measure inside the region you wish to see. Effectively, there is no problem. Adding any multiple of 180 degrees does not materially change the slope of a line. (Think about it! You can even prove that claim.)
One thing you really don't want to do is make that change internally in the code, as that could effectively create large discontinuities for the ODE solver to deal with. But changing it after the solver is done is fine.
  5 个评论
Walter Roberson
Walter Roberson 2022-5-3
We do not have enough information to advise you yet.
Suppose that you are trying to determine the best way to turn an object for some purpose. Suppose you are proceeding nicely and have accelerated the turn up to half a g. You reach the angle limit and... what? Does it slam to a stop harmlessly? Does it slam to a stop damaging it? Does it bounce off but not switch direction of force so it slams it again? Does it bounce off and reverse direction like a ball? Should the system look ahead and see the collision and slow it to a stop at the boundary and then rapidly move to the other edge of the range and then continue the other action?
Is it a situation where you should be doing some longer planning, looking to see if a potential movement would require hitting the edge and if so finding a different path? Is the task to explore to find one way to accomplish a goal, or is it to explore the "best" way to accomplish a goal and for that purpose it would be fine for a given run to say "I gave up because I predict a problem"? ("Thanks, that's good information, I will try something else")?
warnerchang
warnerchang 2022-5-3
Maybe I should not limit the angle, and I will revise the model.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Historical Contests 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by