フィルターのクリア

Multiple Summation of Series using For Loops

1 回表示 (過去 30 日間)
RPS19
RPS19 2019 年 10 月 7 日
コメント済み: RPS19 2019 年 11 月 4 日
Hello all,
I am trying to sum the following series for various positions, y being the position in the function.
The 'r' and 'z' values are known dimensions of a coil, indicating the thickness and height of the coil respectively. The plot that I get from this code is incorrect and I can't figure out why. Is my methodology for executing the series summation for each value of position (y) correct? Any help would be greatly appreciated.
position = -0.1:0.001:0.1;
L = length(position);
Coupl = zeros(1,L);
s = 0;
r = [0.01746 0.0247];
z = [-0.0063 0.0063];
Ac = (r(2) - r(1))*(z(2)-z(1));
Nc = 1500;
Br = 1.31;
Vm = 3.218e-6;
Ff = 0.33;
for y = 1:L
for i=1:2
for j=1:2
s = s + Nc*Br*Vm*Ff/(2*Ac)*((-1)^(i+j)*(log(r(i)+sqrt(r(i)^2+(z(j)-position(y))^2)) - r(i)/sqrt(r(i)^2+(z(j)-position(y))^2)));
end
end
Coupl(y) = s;
end
figure
plot(position,Coupl)
xlabel('Position')
ylabel('Coupling Term')
The correct plot should look similar to the one below:

採用された回答

Daniel M
Daniel M 2019 年 10 月 8 日
Very close. You need to reset the value of s for each y.
I also cleaned it up a bit. This now produces the specified figure.
clearvars
close all
clc
position = -0.1:0.001:0.1;
L = length(position);
Coupl = zeros(1,L);
s = 0;
r = [0.01746 0.0247];
z = [-0.0063 0.0063];
Ac = (r(2) - r(1))*(z(2)-z(1));
Nc = 1500;
Br = 1.31;
Vm = 3.218e-6;
Ff = 0.33;
for y = 1:L
for ii=1:2
for jj=1:2
% simplify the formula a bit
x1 = (-1)^(ii+jj);
Zij = sqrt(r(ii)^2 + (z(jj) - position(y))^2);
x2 = log(r(ii)+Zij);
x3 = r(ii)/Zij;
s = s + x1*(x2 - x3);
end
end
% multiply by a constant once (outside of loop)
s = s * Nc*Br*Vm*Ff/(2*Ac);
Coupl(y) = s;
s = 0; % reset value of s
end
figure
plot(position,Coupl)
xlabel('Position')
ylabel('Coupling Term')
  5 件のコメント
Daniel M
Daniel M 2019 年 10 月 8 日
I do stuff with magnet design so I was just curious.
RPS19
RPS19 2019 年 11 月 4 日
Hi Daniel, Could you possibly take a look at an updated version of this question if you have a chance, I realise I should have just amended this question my apologies for that..

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by