이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to write partial derivatives in MATLAB
조회 수: 8 (최근 30일)
이전 댓글 표시
I am trying to form a 2X2 matrix using partial derivatives i.e. [delf1/delx1, delf1/delx2; delf2/delx1, delf2/delx2]. Not sure how to write it.
댓글 수: 2
John D'Errico
2022년 5월 26일
편집: John D'Errico
2022년 5월 26일
This is strange. @Torsten gave you a simple solution. Your response was that the excercise is so simple, that it should be doable using direct computations. In fact, it is quite simple. So do it.
In fact, you know how to form a matrix, since you wrote that part in your question. So just compute the derivatives. Where is the problem? Do you not know how to use diff? Are you not allowed to use diff? If you can use diff, then do so. If not, then you must understand what the definition of a derivative is, as a limit, and surely you have learned how to approximate a derivative? So what are you not saying? Don't just say it is easy, as you would not be asking the question if it was really that easy for you.
IF the entire thing is too complex for you to do, then take one piece at a time. You have a function (actually, two of them), of two variables. Differentiate each piece with respect to each variable, using whatever means you wish. Then do that 4 times, and put it together.
Ken
2022년 5월 26일
Maybe I didn't explain clearly:
delf1delx1=????;
Not sure what to put on the RHS of the eqn
채택된 답변
Torsten
2022년 5월 26일
댓글 수: 27
Ken
2022년 5월 26일
Thanks. Comment:
This exercise is simple enough, such that you don't need to use any kind of function call like jacobian(). All the exercise is asking for, is to implement the function for the state transition, f = x+u and its derivatives Fx, Fu, which can easily be calculated by hand.
Ken
2022년 5월 26일
Tried, got:
Unrecognized function or variable 'df1dx1'.
Error in solution>@(x,u)[df1dx1,df1dx2;df2dx1,df2dx2] (line 2)
Ken
2022년 5월 26일
I used this:
f = @(x, u) x+u;
Fx = @(x,u) [df1dx1,df1dx2;df2dx1,df2dx2];
Fu = @(x,u) [df1du1,df1du2;df2du1,df2du2];
Ken
2022년 5월 27일
Thanks, still no dice. I guess the problem is to get the estimated position from previous position and motion estimate -
and put this in MATLAB i.e. x(t) =x(t-1) + u(t)*t
Torsten
2022년 5월 27일
편집: Torsten
2022년 5월 27일
I guess the problem is to get the estimated position from previous position and motion estimate -
and put this in MATLAB i.e. x(t) =x(t-1) + u(t)*t
I don't see any relation to your first question.
Maybe you should copy your assignment in here in order not to waste our time.
Ken
2022년 5월 27일
Thanks here is the assignment:
In this simplified example, the state is solely comprised of the position of the robot. We assume that the robot provides some inputs to its locomotion system and employs sensors to determine the resulting change in position, which we will denote as .
Please write the anonymous function that realizes the motion model . For later use, please also implement the anonymous functions and that compute the Jacobian and of the motion model with respect to the state as well as to relative motion measurement respectively.
f = @(x, u) ????;
Fx = @(x,u) ????;
Fu = @(x,u) ????;
Torsten
2022년 5월 27일
And did you write the anonymous function f that realizes the motion model ?
Without f, no Fx and no Fu.
Torsten
2022년 5월 28일
Then Fx = 1, Fu = t.
But what is your question ?
If you want me to deduce f: I can't.
Ken
2022년 6월 12일
편집: Torsten
2022년 6월 12일
This is the problem statement and my solution. Still get error Error "in solution: Line: 7 Column: 3
Unsupported use of the '=' operator. To compare values for equality, use '=='. To specify name-value arguments, check that name is a valid identifier with no surrounding quotes."
f = @(x, u) x+u;
Fx = @(x,u) [1,0];
Fu = @(x,u) [0,1];
%%% SECTION FOR SELF-EVALUATION. PLEASE DO NOT EDIT BELOW THIS LINE %%%
x = [1;2]
x = 2×1
1
2
u = [3;4]
u = 2×1
3
4
f_eval = f(x,u)
f_eval = 2×1
4
6
Fx_eval = Fx(x,u)
Fx_eval = 1×2
1 0
Fu_eval = Fu(x,u)
Fu_eval = 1×2
0 1
Ken
2022년 6월 22일
Still no luck - wrong. Got this comment: The Jacobian of a multivariate function (the output of f is two-dimensional) is a matrix.
Walter Roberson
2022년 6월 22일
You posted that you have
f = @(x, u) x+u;
Fx = @(x,u) [df1dx1,df1dx2;df2dx1,df2dx2];
Fu = @(x,u) [df1du1,df1du2;df2du1,df2du2];
You should be using
f = @(x, u) x+u;
Fx = @(x,u) [df1dx1(x, u), df1dx2(x,u); df2dx1(x, u), df2dx2(x, u)];
Fu = @(x,u) [df1du1(x,u), df1du2(x,u); df2du1(x, u), df2du2(x, u)];
after having defined df1du1 and so on as function handles.
The result will be function handles that will compute the matrices given inputs.
I suspect however that what is expected is that you create a function that takes inputs and returns the jacobian matrix, rather than returning a handle to create the matrix.
Ken
2022년 6월 22일
Thanks, tried it and got:
Undefined function 'df1dx1' for input arguments of type 'double'.
Error in solution>@(x,u)[df1dx1(x,u),df1dx2(x,u);df2dx1(x,u),df2dx2(x,u)] (line 2)
Fx = @(x,u) [df1dx1(x, u), df1dx2(x,u); df2dx1(x, u), df2dx2(x, u )];
Torsten
2022년 6월 22일
I repeat what I already wrote:
You should be using
f = @(x, u) x+u;
Fx = @(x,u) [df1dx1(x,u), df1dx2(x,u); df2dx1(x, u), df2dx2(x, u)];
Fu = @(x,u) [df1du1(x,u), df1du2(x,u); df2du1(x, u), df2du2(x, u)];
after having defined df1dx1 and so on as function handles.
Ken
2022년 6월 22일
This is the problem statement that cannot be changed:
f = @(x, u) ????;
Fx = @(x,u) ????;
Fu = @(x,u) ????;
Walter Roberson
2022년 6월 22일
Is that problem statement incompatible with the forms we show like
Fx = @(x,u) [df1dx1(x,u), df1dx2(x,u); df2dx1(x, u), df2dx2(x, u)];
after having defined df1dx1 and so on as function handles ?
Ken
2022년 6월 22일
I believe that Fx = @(x,u) [1,0]is correct. I guess the problem lies in the first line i.e. f= @(x, u) x+u; This is because the instructor comment was "The Jacobian of a multivariate function (the output of f is two-dimensional) is a matrix."
Ken
2022년 6월 22일
I was given the foll. hint to solve this:
X= f[Xt-1, Ut] , and f=[f1,f2]', X = [x1,x2]', U=[u1,u2]'
Then grad xF is defined as [delf1/delx1 etc....]
similarly grad uF is defined as [del f1/delu1 etc.]
Walter Roberson
2022년 6월 23일
"The Jacobian of a multivariate function (the output of f is two-dimensional) is a matrix."
That is correct.
I guess the problem lies in the first line i.e. f= @(x, u) x+u;
That is not the Jacobian of any function, so it does not matter if it is not a matrix. On the other hand in the quote above, we are told that the output of f is two-dimensional (so, not a vector), so apparently f should be returning a 2d array.
X= f[Xt-1, Ut] , and f=[f1,f2]', X = [x1,x2]', U=[u1,u2]
X seems to be a 2 x 1 column vector, and U seems to be a 1 x 2 row vector, if I read that correctly. In that case, using implicit expansion. x+u woud be (2 x 1) plus (1 x 2) which should give a 2 x 2 result. However, it is not common for formulas to add arrays of different sizes (unless one of the operands is a scalar), so it is not clear that x+u is correct -- either that or else 2 x 1 and 1 x 2 might not be correct.
Walter Roberson
2022년 6월 24일
If x is 2 x 1 and u is 2 x 1, then u+x is 2 x 1, and that contradicts the information we are given that "the output of f is two-dimensional" .
Ken
2022년 6월 24일
Thanks. just wonder about the foll. hint I rec'd and if it can be used to solve this problem:
"First, we're dealing with a discrete system here, so there's no dependency on time t anymore. Further i want to note that the execise gives you x=x[k-1] and u=u[k]. Given the state transition x[k] = x[k-1] + u[k] the solution is as simple as f = @(x, u) x + u. Differentiating this equation by x and u will then give you two very simple, constant matrices as the solution."
Walter Roberson
2022년 6월 25일
syms x [2 1]
syms u [2 1]
f = x + u
f =
jacobian(f, x)
ans =
jacobian(f, u)
ans =
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)