Differentiating Matrices

7 次查看(过去 30 天)
Haast
Haast 2011-10-2
I have a 2 by 2 matrix and i need to differentiate each term in this matrix by each term in another 2 by 2 matrix so that i end up with a 4 by 4 result. Eventually i will be doing the same thing with 20 by 5 matrices. Is there any way of doing this? Can anybody help please?
  4 个评论
Walter Roberson
Walter Roberson 2011-10-5
Pasting the code would be a good start. Commenting the code would help after that.
Haast
Haast 2011-10-10
clc
clear
%% Defining variables
%symbolic variables
syms c11 c12 c21 c22 x y
%array
c_ij = [c11 c12; c21 c22];
%dimensions
L = 20;
W = 20;
T = 0.125;
%unit loads
Nx = 1;
Ny = 1;
Nxy = 1;
%material properties
E = 72.4*10^9;
nu = 0.3;
D = (E*T^3)/(12*(1-nu.^2));
G = E/(2*(1+nu));
%% Defining and differentiating Omega
%Omega
w = c11*sin((pi*x)/L)*sin((pi*y)/W) + c12*sin((pi*x)/L)*sin((2*pi*y)/W) + c21*sin((2*pi*x)/L)*sin((pi*y)/W) + c22*sin((2*pi*x)/L)*sin((2*pi*y)/W);
%derivatives
dw_x = diff(w, x);
dw_y = diff(w, y);
dw_xy = diff(w, x, y);
%second derivatives
dw2_x = diff(dw_x, x);
dw2_y = diff(dw_y, y);
dw2_xy = diff(dw_xy, x, y);
%% FINDING KMN and PMN
F = ((dw2_x + dw2_y)^2)-2*(1-nu)*((dw2_x*dw2_y)-(dw2_xy)^2);
KMN = int(F,x,0,L);
KMN2 = D*int(KMN,y,0,W);
S = (Nx*dw_x^2+Ny*dw_y^2+2*Nxy*dw_xy^2);
PMN = int(S,0,L);
PMN2 = int(PMN,0,W);
%% Differentiation wrt cij
KMNF = diff(KMN2, c_ij);
this works up until i try and do the KMNF :(

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2011-10-3
Is this symbolic or numeric differentiation ? If it is symbolic, is the second matrix containing just one symbol per entry or does it contain expressions? Differentiating with respect to an expression is not easy.

Haast
Haast 2011-10-3
it is symbolic. Actually i realised there was an error in my code and i am trying to differentiate one expression with respect to a matrix. I haven't typed it up here because it is a very long expression but it is essentially an expression in terms of c11 c12 c21 and c22 and i want to differentiate it with respect to each of these and because i am going to eventually be doing the same with many c values i thought the neatest way to set it out would be as a matrix!
  3 个评论
Haast
Haast 2011-10-5
I am sorry I am very much a beginner with MATLAB and have never worked with anything to do with MuPad before. Am I just able to create a new notebook file with Mupad and enter these expressions into it??
Walter Roberson
Walter Roberson 2011-10-5
You could do that, but there are alternatives. For example, at the MATLAB level, you might be able to use
diffs_list = simple(subs('map(proc(thisvar,expression) diff(expression,thisvar) end_proc, indets(YourExpression) minus Type::ConstantIdents, YourExpression)', 'YourExpression', your_symbolic_expression));
Unfortunately I do not have the symbolic toolbox myself, so I am not certain it is possible to activate the internal toolkit map() operation in this manner.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by