A complex form containing constant, linear, quadratic, etc., forms

2 ビュー (過去 30 日間)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2024 年 2 月 1 日
回答済み: Walter Roberson 2024 年 2 月 1 日
Helow,
I am struggling to find a symbolic representation which contains, constant, linear, quadratic, cubic, etc., forms. I believe the best is to explain via example. Consider the following:
N = 3;
syms x X1 a [N 1] real
syms A X2 [N N] real
syms C X3 [N N N] real
syms E [N N N N] real
for i=1:N % Linear interactions
X1(i) = x(i);
end
for i=1:N %Quadratic interactions
for j=1:N
X2(i,j) = x(i)*x(j);
end
end
for i=1:N %Cubic interactions
for j=1:N
for k=1:N
X3(i,j,k) = x(i)*x(j)*x(k);
end
end
end
F = a+A*X1+squeeze(sum(permute(C,[3 2 1]).*repmat(X2,[[1 1 N]]), [1 2]))
F = 
F =
a1 + A1_1*x1 + A1_2*x2 + A1_3*x3 + C1_1_1*x1^2 + C1_2_2*x2^2 + C1_3_3*x3^2 + C1_1_2*x1*x2 + C1_1_3*x1*x3 + C1_2_1*x1*x2 + C1_2_3*x2*x3 + C1_3_1*x1*x3 + C1_3_2*x2*x3
a2 + A2_1*x1 + A2_2*x2 + A2_3*x3 + C2_1_1*x1^2 + C2_2_2*x2^2 + C2_3_3*x3^2 + C2_1_2*x1*x2 + C2_1_3*x1*x3 + C2_2_1*x1*x2 + C2_2_3*x2*x3 + C2_3_1*x1*x3 + C2_3_2*x2*x3
a3 + A3_1*x1 + A3_2*x2 + A3_3*x3 + C3_1_1*x1^2 + C3_2_2*x2^2 + C3_3_3*x3^2 + C3_1_2*x1*x2 + C3_1_3*x1*x3 + C3_2_1*x1*x2 + C3_2_3*x2*x3 + C3_3_1*x1*x3 + C3_3_2*x2*x3
In above, F is a [3 1] multivariate function in which each of its elements is written interms of constant, linear and quadratic interactions. I believe, it should be clear which 'pattern' I mean now. I had a tough time to generate the quadratic terms. I need to expand F in terms of higher-order interactions (cubic, qurtic, etc.). I believe there should be a more elegant way to do what I am seeking.
I appreciate your help in advance!
Babak
  3 件のコメント
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2024 年 2 月 1 日
Yes John
The reason is that here I have a hyper graph. C1_1_2 means the impact of node 1 on node 2. C1_2_1
is about the impact of node 2 on node 1. Of course, from algebraic points of view we can
write (C1_1_2+C1_2_1)*x1*x2. But, if I do so in my code at the end I cannot find which node
has a bigger impact on the other one. So, I need to find the causal relations and this is only
possible if I do not mix things.
Catalytic
Catalytic 2024 年 2 月 1 日
@Mohammad Shojaei Arani you have been posting in this forum for two years. It is high time you learn to format your code.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 2 月 1 日
N = 3;
syms x X1 a [N 1] real
syms A X2 [N N] real
syms C X3 [N N N] real
syms E [N N N N] real
for i=1:N % Linear interactions
X1(i) = x(i);
end
for i=1:N %Quadratic interactions
for j=1:N
X2(i,j) = x(i)*x(j);
end
end
for i=1:N %Cubic interactions
for j=1:N
for k=1:N
X3(i,j,k) = x(i)*x(j)*x(k);
end
end
end
F = a+A*X1+squeeze(sum(permute(C,[3 2 1]).*repmat(X2,[[1 1 N]]), [1 2]))
F = 
collect(F, [x1 x2 x3])
ans = 

カテゴリ

Help Center および File ExchangeFiles and Folders についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by