필터 지우기
필터 지우기

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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by