I need help with this plot
Show older comments
This code should have net B field rotating in opposite directions. I'm at a loss to make it work.
clc
clear all
close
disp('Jerry Walker''s Fantastic Engineering Adventure')
disp('EEL 3216 Problem4.4');
fprintf('\n')
format short
% MATLAB Example of CCW Field Rotation
% M-file to calculate the net magnetic field produced
% by a three-phase stator with currents in normal a-b-c sequence % (not flipped).
% Set up the basic conditions
bmax = 1; % Normalize bmax to 1
freq = 60; % 60 Hz
w = 2*pi*freq; % angular velocity (rad/s)
% First, generate the three component magnetic fields
t = 0:1/60000:1/60;
Baa = sin(w*t) .* (cos(0) + j*sin(0));
Bbb = sin(w*t-2*pi/3) .* (cos(2*pi/3) + j*sin(2*pi/3));
Bcc= sin(w*t+2*pi/3) .* (cos(-2*pi/3) + j*sin(-2*pi/3));
% Calculate Bnet
Bnet = Baa + Bbb + Bcc;
% Calculate a circle representing the expected maximum
% value of Bnet
circle = 1.5 * (cos(w*t) + j*sin(w*t));
% Plot the magnitude and direction of the resulting magnetic
% fields. Note that Baa is black, Bbb is blue, Bcc is
% magneta, and Bnet is red.
% Switch sign for Bbb and Bcc
Btaa = sin(w*t) .* (cos(0) + j*sin(0));
Btbb = sin(w*t+2*pi/3) .* (cos(2*pi/3) + j*sin(2*pi/3));
Btcc= sin(w*t-2*pi/3) .* (cos(-2*pi/3) + j*sin(-2*pi/3));
% Calculate Bnet
Btnet = Btaa + Btbb + Btcc;
% Calculate a circle representing the expected maximum
% value of Bnet
circle = 1.5 * (cos(w*t) + j*sin(w*t));
% Plot the magnitude and direction of the resulting magnetic
% fields. Note that Baa is black, Bbb is blue, Bcc is
% magneta, and Bnet is red.
for ii = 1:length(t) % Plot the reference circle
subplot(2,1,1)
plot(circle,'k');
hold on;
% Plot the four magnetic fields
plot([0 real(Baa(ii))],[0 imag(Baa(ii))],'k','LineWidth',2);
plot([0 real(Bbb(ii))],[0 imag(Bbb(ii))],'b','LineWidth',2);
plot([0 real(Bcc(ii))],[0 imag(Bcc(ii))],'m','LineWidth',2);
plot([0 real(Bnet(ii))],[0 imag(Bnet(ii))],'r','LineWidth',3);
legend('Baa','Bbb','Bcc','Bnet')
axis square;
axis([-2 2 -2 2]);
title('Magnetic Flux Versus Time');
drawnow;
% Plot the reference circle
subplot(2,1,2)
plot(circle,'k');
% Plot the four magnetic fields
plot([0 real(Btaa(ii))],[0 imag(Btaa(ii))],'k','LineWidth',2);
plot([0 real(Btbb(ii))],[0 imag(Btbb(ii))],'b','LineWidth',2);
plot([0 real(Btcc(ii))],[0 imag(Btcc(ii))],'m','LineWidth',2);
plot([0 real(Btnet(ii))],[0 imag(Btnet(ii))],'r','LineWidth',3);
legend('Btaa','Btbb','Btcc','Btnet')
axis square;
axis([-2 2 -2 2]);
title('Magnetic Flux Versus Time');
drawnow;
hold off;
end
Answers (1)
Categories
Find more on Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!