Effacer les filtres
Effacer les filtres

Multiple Summation of Series using For Loops

1 vue (au cours des 30 derniers jours)
RPS19
RPS19 le 7 Oct 2019
Commenté : RPS19 le 4 Nov 2019
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:

Réponse acceptée

Daniel M
Daniel M le 8 Oct 2019
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 commentaires
Daniel M
Daniel M le 8 Oct 2019
I do stuff with magnet design so I was just curious.
RPS19
RPS19 le 4 Nov 2019
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..

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by