I want to compute the Jacobian of a function in Matlab

In summary, the conversation discusses a function and the desire to numerically compute its Jacobian. One method is presented, but there is a suggestion to use the symbolic toolbox in MATLAB for a more exact solution. The jacobian command is recommended to calculate the Jacobian matrix for the function.
  • #1
hunt_mat
Homework Helper
1,782
32
Hi,

I have a function of the form:
function r=d(f,j)
if (j==1)
r=3*f(1)+f(3)*f(2)-3;
elseif(j==2)
r=f(1)+2*f(2)-4;
else
r=f(1)*f(2)*f(3)-1;
end

and I would like to be able to numerically compute the Jacobian for such a function. I have a method of computing the Jacobian but I am not convinced that it is giving the right answer though.

for i=1:3
for j=1:3
T=zeros(3,1);
T(j)=dd;
J(i,j)=(d(f+T,i)-d(f,i))/dd; %This is the jacobian
end
end

Does anyone have anything better?
 
  • Like
Likes tutordelhi
Physics news on Phys.org
  • #2
Yes, you can use the symbolic toolbox in MATLAB to compute the Jacobian symbolically. This will give you a more exact solution and will save you the effort of manually computing the Jacobian. You can do this by defining a symbolic vector of variables (f) and then using the jacobian command to calculate the Jacobian of your function d with respect to f. For example, if your vector is f=[f1;f2;f3], then you can use the following command:J=jacobian(d,[f1;f2;f3]) This will give you the Jacobian matrix for your function d.
 

Related to I want to compute the Jacobian of a function in Matlab

What is the purpose of computing the Jacobian of a function in Matlab?

The Jacobian of a function in Matlab is used to find the rate of change of a multivariable function at a specific point. It helps to understand how the function behaves in different directions at that point.

How do I compute the Jacobian of a function in Matlab?

To compute the Jacobian of a function in Matlab, you can use the built-in function "jacobian" or you can write your own code using the symbolic math toolbox. The function takes in the function expression and the variables as inputs and returns the Jacobian matrix.

What does the Jacobian matrix represent?

The Jacobian matrix represents the partial derivatives of a multivariable function. Each entry in the matrix represents the rate of change of the function with respect to a specific variable at a specific point.

Can I compute the Jacobian for any type of function in Matlab?

Yes, you can compute the Jacobian for any type of function in Matlab as long as the function is differentiable. This means that the function must have continuous partial derivatives at the point of interest.

How can I use the Jacobian matrix in my calculations?

The Jacobian matrix can be used in various calculations such as finding critical points, determining the direction of steepest ascent, and solving systems of differential equations. It is a useful tool for optimization and understanding the behavior of multivariable functions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
78
Replies
2
Views
794
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
19
Views
142
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • Calculus and Beyond Homework Help
Replies
2
Views
211
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
Back
Top