Undefined function or variable 'dx'.

4 vues (au cours des 30 derniers jours)
Mustafa Abdelfattah
Mustafa Abdelfattah le 11 Avr 2024
Réponse apportée : Aniket le 7 Août 2024
jacobi = [dx(f1,x1,y1) dy(f1,x1,y1);
dx(f2,x1,y1) dy(f2,x1,y1)]; %jacobian matrix that obtains partial dervatives
  2 commentaires
John D'Errico
John D'Errico le 11 Avr 2024
Modifié(e) : John D'Errico le 11 Avr 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 le 11 Avr 2024
syms x y
f1 = x^2+y^3;
f2 = sin(x) + exp(y);
f = [f1,f2];
jacobian(f)
ans = 

Connectez-vous pour commenter.

Réponses (1)

Aniket
Aniket le 7 Août 2024
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!

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by