Undefined function or variable 'dx'.

14 次查看(过去 30 天)
Mustafa Abdelfattah
回答: Aniket 2024-8-7,14:25
jacobi = [dx(f1,x1,y1) dy(f1,x1,y1);
dx(f2,x1,y1) dy(f2,x1,y1)]; %jacobian matrix that obtains partial dervatives
  2 个评论
John D'Errico
John D'Errico 2024-4-11
编辑:John D'Errico 2024-4-11
You cannot just write dx, and hope that MATLAB will be smart enough to differentiate something. The mindreading toolbox is never working when you need it.
I would strongly suggest you first spend some time with the MATLAB Onramp tutororial. Then spend some time in learnign how to use the symbolic toolbox. diff can differentiate an expression.
Torsten
Torsten 2024-4-11
syms x y
f1 = x^2+y^3;
f2 = sin(x) + exp(y);
f = [f1,f2];
jacobian(f)
ans = 

请先登录,再进行评论。

回答(1 个)

Aniket
Aniket 2024-8-7,14:25
The error is thrown because `dx` is not a predefined function in MATLAB for differentiation.
Here are two ways to calculate the Jacobian matrix:
  1. Using Symbolic Differentiation (`diff`)
% Define symbolic variables
syms x y
% Define the functions
f1 = x^2 + y^2 - 1;
f2 = x^2 - y;
% Compute the Jacobian matrix using symbolic differentiation
jacobi = [diff(f1, x), diff(f1, y);
diff(f2, x), diff(f2, y)];
2. Using the Inbuilt `jacobian` Function
% Define symbolic variables
syms x y
% Define the functions
f1 = x^2 + y^2 - 1;
f2 = x^2 - y;
% Create a vector of the functions
F = [f1; f2];
% Compute the Jacobian matrix using the inbuilt function
jacobi = jacobian(F, [x, y]);
Both methods will yield the same Jacobian matrix.
For more information, refer to the following MATLAB documentation
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by