Undefined function or variable 'dx'.

4 visualizzazioni (ultimi 30 giorni)
Mustafa Abdelfattah
Mustafa Abdelfattah il 11 Apr 2024
Risposto: Aniket il 7 Ago 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 Commenti
John D'Errico
John D'Errico il 11 Apr 2024
Modificato: John D'Errico il 11 Apr 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 il 11 Apr 2024
syms x y
f1 = x^2+y^3;
f2 = sin(x) + exp(y);
f = [f1,f2];
jacobian(f)
ans = 

Accedi per commentare.

Risposte (1)

Aniket
Aniket il 7 Ago 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!

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by