Differentiating Matrices

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

bym
bym 2011년 10월 2일
what have you got so far?
Haast
Haast 2011년 10월 5일
sorry what do you mean? You want me to paste the code?
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일

0 개 추천

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일

0 개 추천

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

Walter Roberson
Walter Roberson 2011년 10월 3일
At the MuPad level (not in MATLAB directly):
exprvars := indets(YourExpression) minus Type::ConstantIdents:
partialdiffs := map((thisvar,expression) -> diff(expression,thisvar), exprvars, YourExpression);
Then partialdiffs will be the partial differentials and exprvars will be the variables used for the partials.
You should be able to turn this into something you can feval(symengine,...) without great difficulty.
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.

댓글을 달려면 로그인하십시오.

질문:

2011년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by