フィルターのクリア

How to avoid error in anonymous function

1 回表示 (過去 30 日間)
Ken
Ken 2022 年 5 月 6 日
コメント済み: Walter Roberson 2022 年 5 月 9 日
I am trying to predict the robot position using the 3 steps below but get error:
Fx = @(x,u) jacobian(f(x,u),x);
Fu = @(x,u) jacobian(f(x,u),y);
f = @(x, u) Fx*x(t-1) +Fu*u(t-1);
  2 件のコメント
Ken
Ken 2022 年 5 月 7 日
That's the way given in the problem i.e. using 3 anonymous functions
Walter Roberson
Walter Roberson 2022 年 5 月 7 日
The jacobian of a function with respect to a single variable is the same as the derivative with respect to that variable. So Fx is diff(f, x) and Fu is diff(f, y). But f is not a function of y, so diff(f, y) is 0. So your f simplifies to
f = diff(f, x) * x(t-1)
Except that x is obviously a function of t, so you are taking the derivative with respect to a function.
By examination it becomes clear that the simplest function that can satisfy this is f(x, u) = 0, and there is no real reason to try for anything more complicated.

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2022 年 5 月 6 日
f = @(x, u) Fx(x,u)*x(t-1) + Fu(x,u)*u(t-1);
  10 件のコメント
Ken
Ken 2022 年 5 月 7 日
This is a comment from someone who got it. Not sure how useful; I could not replicate symbols used correctly.
As per lecture slide, the position at time t is the position at time (t-1) plus the displacement from the motion model (using motor encoders etc).
So, X_hat = f(Xt-1,ut with f=[f1;f2] , X=[x1;x2] and U=[u1;u2]
Then Deltax.f is defined as (delf1/delx1,delf2/delx2;delf2/delx1,delf2/delx2)
Similar for Deltau.f
Torsten
Torsten 2022 年 5 月 7 日
You still did not answer the main question: Is f a function, a function handle ? Is f difficult such that derivatives are only available by numerical differencing or easy such that it's possible to get them analytically ?

サインインしてコメントする。


Ken
Ken 2022 年 5 月 7 日
Tried as suggested, error Undefined function 'Fx' for input arguments of type 'double'.:
f = @(x, u) Fx(x,u)*x(t-1) + Fu(x,u)*u(t-1);
Fx = @(x,u) jacobian(f(x,u),x);
Fu = @(x,u) jacobian(f(x,u),y);
  5 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 9 日
編集済み: Walter Roberson 2022 年 5 月 9 日
What you want to do cannot be programmed in MATLAB.
This is a different statement than saying that the assignment cannot be completed in MATLAB.
In MATLAB it is impossible for an anonymous function to refer to itself. I explained that in detail earlier. To refresh your memory:
At the time you build the anonymous function that will be assigned to f, MATLAB will look at all mentioned functions and variables, and will take copies of the variables that exist (except for the named parameters), and will mark the other ones as undefined. f does not exist at the time the right hand side of the @ is evaluated, so it gets marked as undefined in the anonymous function. The f that the anonymous function gets assigned to has no connection to the f inside the anonymous function. When you execute the anonymous function, at the point that it needs to call f, it sees that inside of the anonymous function that f is marked as undefined and it will error. Under no circumstances will it look to say "Oh, but f is defined now, we will use that!". NEVER
Walter Roberson
Walter Roberson 2022 年 5 月 9 日
Your anonymous function f cannot refer to f or the jacobian of f.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by