Symbolic Functions of Symbolic Vectors
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a function
where x and y are both vectors of an arbitrary length. The function d is a small part which appears many times in a larger function and I'd like to be able to have the derivatives of d show up as
as opposed to the behavior that occurs if I fully define
. However, if I try to do this with something like:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282926/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282931/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282971/image.png)
syms d(x,y) real
syms x y real [1 4]
I'll end up with vectors:
x = [x1, x2, x3, x4]
y = [y1, y2, y3, y4]
Which means that if I take the Jacobian of this function I get:
jacobian(d,x) = [0,0,0,0]
As opposed to something like:
jacobian(d,x) = [diff(d,x1), diff(d,x2), ....]
Which is my desired behavior.
Additionally, if I use syntax like:
syms x [1 4]
syms d(x) [1 4] matrix keepargs
jacobian(d,x)
I get the error:
Incorrect number or types of inputs or outputs for function 'jacobian'.
And if I use the syntax:
syms x [1 4] matrix
syms d(x) [1 4] matrix keepargs
diff(d,x)
I get the output:
diff(d(x), x)
Calling Jacobian gives the same error as before and attempting to differentiate w/r.t. any of the variables within symmatrix x throws an error saying it isn't a recognized variable.
Does anyone know how to get that behavior? In this case would I need to explicitly define something like
?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1282961/image.png)
I'm working on r2023a right now if that helps.
댓글 수: 0
채택된 답변
Raghvi
2023년 2월 14일
I understand that you are trying to figure out the partial derivatives of your function using the “Jacobian” function, and your desired output is jacobian(d,x) = [diff(d,x1), diff(d,x2), ....]
The following piece of code worked for me:
>> syms x y [1 4] real
>> d(x,y)= sqrt((x-x0).^2 + (y-y0).^2);
>> jacobian(d,x)
For more information on Jacobian, you can refer to the documentation:
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!