A complex form containing constant, linear, quadratic, etc., forms
2 ビュー (過去 30 日間)
古いコメントを表示
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 =
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 件のコメント
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
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]))
collect(F, [x1 x2 x3])
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Files and Folders についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!