Gradient of vector-valued function

10 views (last 30 days)
Moritz Schulze
Moritz Schulze on 24 Oct 2017
Answered: VBBV on 17 Dec 2022
Code below throws an error. How is it possible to get the gradient for a vector-valued function?
syms a b1 b2 t
mfcn = matlabFunction(b1.*t^2+b2.*t, 'Vars', {[b1,b2],t})
gradient(mfcn,t)

Answers (2)

Moritz Schulze
Moritz Schulze on 24 Oct 2017
syms a b1 b2 t
mfcn = matlabFunction(b1.*t^2+b2.*t)
gradient(mfcn,t)
This works on the contrary.

VBBV
VBBV on 17 Dec 2022
use diff instead of gradient which is equivalent for gradient operation for symbolic expressions
syms a b1 b2 t
mfcn = matlabFunction(b1.*t.^2+b2.*t,'Vars', {b1,b2,t})
mfcn = function_handle with value:
@(b1,b2,t)b2.*t+b1.*t.^2
diff(mfcn,t) % use diff instead of gradient
ans = 

Community Treasure Hunt

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

Start Hunting!