Undefined function or variable 'dx'.

3 Ansichten (letzte 30 Tage)
Mustafa Abdelfattah
Mustafa Abdelfattah am 11 Apr. 2024
Beantwortet: Aniket am 7 Aug. 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 Kommentare
John D'Errico
John D'Errico am 11 Apr. 2024
Bearbeitet: John D'Errico am 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 am 11 Apr. 2024
syms x y
f1 = x^2+y^3;
f2 = sin(x) + exp(y);
f = [f1,f2];
jacobian(f)
ans = 

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Aniket
Aniket am 7 Aug. 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!

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by