Borrar filtros
Borrar filtros

Undefined function or variable 'dx'.

14 visualizaciones (últimos 30 días)
Mustafa Abdelfattah
Mustafa Abdelfattah el 11 de Abr. de 2024
Respondida: Aniket el 7 de Ag. de 2024 a las 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 comentarios
John D'Errico
John D'Errico el 11 de Abr. de 2024
Editada: John D'Errico el 11 de Abr. de 2024
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 el 11 de Abr. de 2024
syms x y
f1 = x^2+y^3;
f2 = sin(x) + exp(y);
f = [f1,f2];
jacobian(f)
ans = 

Iniciar sesión para comentar.

Respuestas (1)

Aniket
Aniket el 7 de Ag. de 2024 a las 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!

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by