summaryrefslogtreecommitdiff
path: root/src/abgabe.org
blob: 772d04d1c0df545ee972a54d9e10f8d24e02086a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#+TITLE: Übungsblatt 5 - Aufgabe 3
#+HTML_HEAD_EXTRA: <meta name="robots" content="noindex">
#+SETUPFILE: ../options.org

[[https://thomaslabs.org/shortcoil.m][Quellcode herunterladen]]

* Ergebnisse des Programms
[[https://thomaslabs.org/media/betrag.png]]

[[https://thomaslabs.org/media/richtung.png]]

[[https://thomaslabs.org/media/spulenachse.png]]
* Octave / Matlab Quellcode
#+BEGIN_SRC octave
  clear all;
  close all;
  clc;

  %% length of the observed region in m
  len = 40e-3; %m
  len = len / 2; %we shall go from -len to +len
  %% number of points in x- and z-direction
  N_space = 50;
  %% number of points for integration along coil
  N_phi = 250;
  %% radius
  R = 5e-3; %m
  %% length
  L = 23e-3; %m
  %% number of windings
  N = 5;
  %% current
  I = 8; %A
  %% vacuumpermeability
  mu0 = 4 * pi * 1e-7; %Vs/Am

  %% define grid
  z = linspace(-len, len, N_space); %m
  x = linspace(-len, len, N_space); %m

  %% parameter of coil-wire-path-paramtrisation
  phi = linspace(0, N * 2 * pi, N_phi);
  dphi = phi(2) - phi(1);

  %% Precalculate cos and sin
  p_sin = sin(phi);
  p_cos = cos(phi);

  %% loop through all x-z-points
  for iz = 1 : N_space
    for ix = 1 : N_space
      %% r of this x-z-point
      r = [x(ix); 0; z(iz)];
      B = [0; 0; 0];

      %% Riemann sum along the coil
      for ip = 1 : N_phi
        %% Point along the coil
        l = [R * p_cos(ip); R * p_sin(ip); ip * L / N_phi - L / 2];
        %% Vector tangent to the coil of length dl = R * dphi
        dl = [- R * p_sin(ip); R * p_cos(ip); L / 2 / N / pi];
        dl = (R * dphi / norm(dl)) * dl;
        %% Vector from the coil to the x-z-point
        rp = r - l;
        %% Add dB
        B = B + (mu0 / 4 / pi) * I * (1 / norm(rp) ^ 3) * cross(dl, rp);
      end

      B_X(iz, ix) = B(1);
      B_Y(iz, ix) = B(2);
      B_Z(iz, ix) = B(3);
    end
  end

  figure('Name', 'Richtung der Flußdichte', 'NumberTitle', 'off');
  quiver(x * 1e3, z * 1e3, B_X ./ sqrt(B_X .^ 2 + B_Z .^ 2),
         B_Z ./ sqrt(B_X .^ 2 + B_Z .^ 2));
  title('Richtung der Flußdichte')
  xlabel('x [mm]')
  ylabel('z [mm]')
  axis image
  saveas(gca, 'richtung.png')

  betrag = sqrt(B_X .^ 2 + B_Y .^ 2 + B_Z .^ 2)
  figure('Name', 'Betrag der Flußdichte', 'NumberTitle', 'off');
  imagesc(x * 1e3, z * 1e3, betrag);
  title('Betrag der Flußdichte');
  xlabel('x [mm]')
  ylabel('z [mm]')
  colormap(gray);
  colorbar('title', 'B [T]');
  saveas(gca, 'betrag.png')

  figure('Name', 'Flußdichte entlang Spulenachse', 'NumberTitle', 'off');
  B_2 = B_Z(:, round((N_space - 1) / 2));
  plot(x * 1e3, B_2);
  title('Flußdichte entlang Spulenachse');
  xlabel('z [mm]');
  ylabel('Flußdichte [T]');
  saveas(gca, 'spulenachse.png')
#+END_SRC