%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Lektion 3                              %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Uppgift 3.1
clear all
clc

N = 450;
R = 2.8;
Ac = 32e-4;
g = 0.18e-3;
M = 95; % kg
G = 9.81;
mu0 = 4*pi*1e-7;

% a)
I = 2*g/N*sqrt(M*G/(mu0*Ac))
V = R*I

% b)
g = [0.1:0.01:1]'*1e-3;
f = -1/4*N^2*mu0*Ac*I^2*g.^-2;
plot(g,f)
xlabel('luftgap [m]')
ylabel('lyftkraft [N]')
grid

% c) 
mur = 1000;
lc = 0.5;
Rtot = 2*g/(mu0*Ac) + lc/(mu0*mur*Ac);
fc = -(N*I./Rtot).^2 /(mu0*Ac);
plot(g,[f fc])
legend('ideal','icke-ideal','Location','SouthEast')
xlabel('luftgap [m]')
ylabel('lyftkraft [N]')
grid


%% Uppgift 3.3

% 
x = [0:0.01:pi]';
I = [5 sqrt(50) 10];
Tavg = -2.1e-3*I.^2.*sin(x);
Tf = -0.1 + 0.2/pi*x
plot(x*180/pi,[Tavg Tf])
axis([0 180 -0.25 0])
grid
%%
syms th
I = [0:0.1:10];
for i = 1:length(I)
th0(i) =  180/pi*vpasolve( -2.1e-3*I(i)^2*sin(th) +0.1 - 0.2/pi*th == 0, th);
end
%%
plot(I,th0)
xlabel('Str?m [A]')
ylabel('Vinkel [grader]')
axis([0 10 0 90])
grid
