フィルターのクリア

How to write the sum of several matrices in Matlab ?

4 ビュー (過去 30 日間)
Djamel
Djamel 2024 年 4 月 27 日
コメント済み: Walter Roberson 2024 年 4 月 29 日
We have the sequence of matrices
B(i,j,n)=2/N exp⁡(-cn^2 ) sin⁡(nx_i ) sin⁡(n y_j )
where N and n are integers ,x_i and y_ji are real numbers in the
interval [0 ,1] and c is a real parameter strictly positive.
We pose
A(c)= ∑_B(n) for n=1,....,10
How to write in Matlab the sum A(c) ?

回答 (2 件)

Voss
Voss 2024 年 4 月 27 日
A = sum(B,3);
  1 件のコメント
Voss
Voss 2024 年 4 月 27 日
I you don't have B already, here's how you can get it:
% your numbers go here:
N = 10;
nx = 7;
ny = 6;
x = rand(1,nx);
y = rand(1,ny);
c = rand();
n = reshape(1:N,1,1,[]);
B = 2/N.*exp(-c.*n.^2).*sin(n.*x(:)).*sin(n.*y(:).');
size(B)
ans = 1x3
7 6 10
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A = sum(B,3)
A = 7x6
0.0031 0.0035 0.0015 0.0018 0.0029 0.0033 0.0375 0.0429 0.0181 0.0225 0.0352 0.0411 0.0106 0.0121 0.0052 0.0064 0.0100 0.0116 0.0002 0.0002 0.0001 0.0001 0.0001 0.0002 0.0355 0.0406 0.0172 0.0213 0.0333 0.0389 0.0067 0.0077 0.0033 0.0041 0.0063 0.0074 0.0037 0.0043 0.0018 0.0023 0.0035 0.0041
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

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


Walter Roberson
Walter Roberson 2024 年 4 月 27 日
syms c N
num_i = 3; %adjust as needed
num_j = 4; %adjust as needed
num_n = 10;
syms x [num_i 1]
syms y [1 num_j]
x = repmat(x, 1, num_j, num_n);
y = repmat(y, num_i, 1, num_n);
n = repmat(reshape(1:num_n, 1, 1, []), num_i, num_j, 1);
B = 2/N .* exp(-c .* n) .* sin(n .* x) .* sin(n .* y);
A = sum(B, 3)
A = 
  6 件のコメント
Djamel
Djamel 2024 年 4 月 29 日
Thank you so much. It worked
Walter Roberson
Walter Roberson 2024 年 4 月 29 日
N = 7;
i = 1:N;
x_i = (i-1/2)/N * pi;
y_i = (i-1/2)/N * pi;
syms c
num_i = length(x_i);
num_j = length(y_i);
num_n = 10;
syms x [num_i 1]
syms y [1 num_j]
xG = repmat(x, 1, num_j, num_n);
yG = repmat(y, num_i, 1, num_n);
nG = repmat(reshape(1:num_n, 1, 1, []), num_i, num_j, 1);
B = 2/N .* exp(-c .* nG) .* sin(nG .* xG) .* sin(nG .* yG);
A = sum(B, 3)
A = 
Ad = vpa(subs(subs(A, x, x_i.'), y, y_i), 5)
Ad = 

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by