Calculating magnetic field lines and simulation of the motion of a charged particle

How can I simulate a magnetic field with several conductors?
In the function calcMField I want to calculate the magnetic field, but i don't know how.
classdef cMField
properties
mXY = []; % Koordinaten der Ladungen [x1, y1; x2, y2...]
vI = []; % Ströme [I1, I2, I3]' (Spaltenvektor)
%vV = []; % Initialisierung jeweils mit [] also 0
end
properties(Dependent = true) % Get und Set-Property festlegen
ITotal % Gesamtstrom
N % Anzahl der Ladungen
end
properties(Constant = true) % Konstante
Mu0 = 4*pi*10^-7
RMin = 0.1; % Einschränkung für Ladungsvektoren
end
methods
function ioO = cMField(imXY, ivI)
ioO.mXY = imXY;
ioO.vI = ivI;
%ioO.vV = ivV;
end
function iITotal = get.ITotal(ioO)
iITotal = sum(ioO.vI);
end
function iN = get.N(ioO)
iN = numel(ioO.vI);
end
function [iHp iHn] = plotCharge(ioO)
vbPosCharge = ioO.vI > 0;
% Liefere mir nur die positiven Ladungen
iHp = plot(ioO.mXY(vbPosCharge,1), ioO.mXY(vbPosCharge,2),'ro'); hold on
% Plotten von positiven X- und Y-Werten der Ladungen)
iHn = plot(ioO.mXY(~vbPosCharge,1), ioO.mXY(~vbPosCharge,2),'bo'); hold off
% Plotten von negativen X- und Y-Werten der Ladungen)
if nargout == 0,
% nargout "gibt die Anzahl der Rückgabewerte zurück"
clear iHp iHn;
end
end
function [imE imX imY] = calcMField(ioO, ivX, ivY)
[imX imY] = meshgrid(ivX, ivY);
imE = zeros([size(imX) 2]);
for CntI = 1:ioO.N,
I = ioO.vI(CntI);
X = ioO.mXY(CntI, 1); % X-Werte an 1.Stelle der Matrix
Y = ioO.mXY(CntI, 2); % Y-Werte an 2.Stelle der Matrix
%V = ioO.vV(CntQ);
mRx = imX - X; % Abstand der X-Ladungspunkte
mRy = imY - Y; % Abstand der Y-Ladungspunkte
mR = sqrt(mRx.^2+mRy.^2);
mRichtung = mR ./ norm(mR);
% Euklidscher Abstand zwischen den mRx und den mRy
mR(mR<cMField.RMin) = NaN;
% Es sollen nicht alle Vektoren angezeigt werden.
% Vektoren nah bei der Ladung werden ausgeschlossen
%mEmag = cMField.Mu0 * I / 2 / pi ./ mR;
mEmag = cMField.Mu0 * I / 2 / pi ./ mR * mRichtung;
imE(:,:,1) = mRx .* mEmag + imE(:,:,1);
imE(:,:,2) = mRy .* mEmag + imE(:,:,2);
end
end
function iH = plotMField(ioO, ivX, ivY)
[mE mX mY] = ioO.calcMField(ivX, ivY);
iH = quiver(mX, mY, mE(:,:,1), mE(:,:,2), 1);
% quiver zeichnet grafische Vektoren
% Wo stehen die X und Y-Werte
% dann wie lang sind die Vektoren x und y
% 0 ist automatische Skalierung durch MatLab
xlabel('x'), ylabel('y')
if nargout == 0, clear iH, end
end
function insertProbeladung(ioO, iX, iY, iQ)
end
end
end

Answers (0)

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Asked:

on 6 Aug 2012

Community Treasure Hunt

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

Start Hunting!