简体   繁体   中英

How to find the Jacobian of my function in Matlab?

I have the following function in Matlab:

f = @(x)[x(1,:)+2*x(2,:)+x(3,:);x(1,:).^3+x(2,:).^2+3*x(3,:)]

How can I find the Jacobian matrix of this function in Matlab?

I have tried using the function jacobian, but I don't get it to work for this specific function. Can someone help me with the correct arguments?

as @dasdingonesin already wrote, you need to use the symbolic toolbox like this:

syms x y z;
f = [x+2*y+z, x^3+y^2+3*z];
gradf = jacobian(f, [x,y,z])

This results in:

gradf =

[     1,   2, 1]
[ 3*x^2, 2*y, 3]

By the way: If you need the jacobian in a solver, you can convert that symbolic function back into a regular MATLAB function using matlabFunction . There is also a nice tutorial about this topic available .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM