Differentiate a 5*5 symbolic matrix by a 5*1 symbolic vector

1 Ansicht (letzte 30 Tage)
Tony Cheng
Tony Cheng am 14 Dez. 2018
Kommentiert: Walter Roberson am 20 Dez. 2018
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!

Antworten (3)

Walter Roberson
Walter Roberson am 14 Dez. 2018
  7 Kommentare
Tony Cheng
Tony Cheng am 20 Dez. 2018
Hi Walter,
These days I hv tried to use arrayfun to make the codes more compact than those with for loop and diff code as shown in the figure. However, according to the syntax of arrayfun, I really do not know how to make it.
Could you pls write a command using arrayfun based on its syntax?
Here I hv a 5*5 matrix A, a 5*1 vector dd, and I want to derive .
A and dd are both symbolic. and elements in A are composed of the five elements in dd.
Thank you very much for your great help!
Walter Roberson
Walter Roberson am 20 Dez. 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]);

Melden Sie sich an, um zu kommentieren.


madhan ravi
madhan ravi am 14 Dez. 2018

Tony Cheng
Tony Cheng am 14 Dez. 2018
diff can be used to differentiate a scalar or vector by a scalar, but not differentiate a matrix by a vector.
  5 Kommentare
madhan ravi
madhan ravi am 14 Dez. 2018
Fine ,understood now , what would be your desired result (post the output that you expect from the example above)?
Tony Cheng
Tony Cheng am 14 Dez. 2018
I have a solution like this.
捕获1.JPG

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by