Differentiate a 5*5 symbolic matrix by a 5*1 symbolic vector
Show older comments
Hi there,
Here I have a symbolic matrix A with a size of 5*5. The elements inside is composed of 5 symbolic variables , i.e., a,b,c,d,e. These 5 varibales together make a 5*1 vector q =[a;b;c;d;e].
During the computation in the project, I need to compute the differentation of A by q, i.e.,
.
Is there any command can be used to realize that?
Thanks very much!
Answers (3)
Walter Roberson
on 14 Dec 2018
1 vote
7 Comments
madhan ravi
on 14 Dec 2018
+1 , that makes everything clear
Tony Cheng
on 14 Dec 2018
Walter Roberson
on 14 Dec 2018
arrayfun(@(a) gradient(a,v), A, 'uniform', 0)
Tony Cheng
on 17 Dec 2018
Edited: Walter Roberson
on 20 Dec 2018
Walter Roberson
on 17 Dec 2018
"Here I have a symbolic matrix A with a size of 5*5"
Tony Cheng
on 20 Dec 2018
Walter Roberson
on 20 Dec 2018
dd = sym('d', [1 5]);
rng(0); P1 = randi([-2 2],5,5); P2 = randi([-2 2],5,5); P3 = randi([-2 2],5,5); P4 = randi([-2 2],5,5); P5 = randi([-2 2], 5,5);
A = dd(1).^P1 .* dd(2).^P2 .* dd(3).^P3 .* dd(4).^P4 .* dd(5).^P5;
%A is now 5 x 5 involving the 5 different varialbes that are stored in dd
G = arrayfun(@(f) gradient(f, dd), A, 'uniform', 0);
%G is now a 5 x 5 cell array, each entry of which is the gradient of
%the corresponding entry of A with respect to the 5 different variables in dd
%if you want five panes of 5 x 5, one plane for each variable in dd, then
planes = permute(reshape(cat(3,G{:}),5,5,5),[2 3 1]);
madhan ravi
on 14 Dec 2018
diff() %?
Tony Cheng
on 14 Dec 2018
0 votes
5 Comments
madhan ravi
on 14 Dec 2018
can you upload the sample of your vector and matrix ?
Tony Cheng
on 14 Dec 2018
Edited: madhan ravi
on 14 Dec 2018
Tony Cheng
on 14 Dec 2018
madhan ravi
on 14 Dec 2018
Fine ,understood now , what would be your desired result (post the output that you expect from the example above)?
Tony Cheng
on 14 Dec 2018
Categories
Find more on Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

