









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
matlab code for exercise coding
Typology: Exercises
1 / 16
This page cannot be seen from the preview
Don't miss anything!










close all; clear all; % Khai bao bien symbolic syms vx ix vC vL vxn ixn vCn vLn k a w t L C % Phuong trinh dong dien ix = k * t^2 * exp(-a*t) * sin(w * t); % Thay the cac tham so vao phuong trinh dong dien ixn = subs(ix, [k a w], [3 2 1]); % Tao hinh 1 figure(1); grid on; hold on; % Ve dong dien trong khoang thoi gian [0, 10] h1 = ezplot(ixn, [0 10]); % Thiet lap thuoc tinh cho hinh 1 ax1 = gca; set(ax1, 'XLim', [0 10]); set(ax1, 'YLim', [-0.1 0.4]); set(ax1, 'XColor', 'k', 'YColor', 'k');
set(get(ax1, 'XLabel'), 'String', 'Thoi gian - s', 'FontSize', 18); set(get(ax1, 'YLabel'), 'String', 'Dong - A', 'FontSize', 18); set(ax1, 'FontSize', 14, 'Box', 'On'); set(h1, 'LineWidth', 2); title(ax1,'Dong dien trong mach'); % Tinh dien ap tren cuon cam L vL = L * diff(ix, t); vL = simplify(vL); % Tinh dien ap tren tu dien C vC = (1/C) * int(ix, t); % Ap dung dinh luat KVL vx = vC + vL; % Thay the cac tham so vao cac phuong trinh dien ap vLn = subs(vL, [k a w L C], [3 2 1 0.5 1]); vCn = subs(vC, [k a w L C], [3 2 1 0.5 1]); vxn = subs(vx, [k a w L C], [3 2 1 0.5 1]); % Tao hinh 2 figure(2); hold on; grid on; % Ve dien ap trong khoang thoi gian [0, 10]
eq = (R * C) * diff(i, t) + i - diff(V, t) ; it = dsolve(eq, i(0) == V/R); vt = 1/C*int(it,t,0,t) disp(it); disp(vt); figure(1),hold on,grid on;; itn= subs(it,[R C V],[1e3 1e-6 1]); h1 = ezplot(itn, [0 0.05]); itn= subs(it,[R C V],[5e3 1e-6 1]); h2 = ezplot(itn, [0 0.05]); itn= subs(it,[R C V],[10e3 1e-6 1]); h3 = ezplot(itn, [0 0.05]); xlabel('Time (s)'); ylabel('Current (A)'); title('Do thi I'); set(h1, 'LineWidth', 3, 'LineStyle', '-'); set(h2, 'LineWidth', 3, 'LineStyle', '--'); set(h3, 'LineWidth', 3, 'LineStyle', ':'); axis([0 0.05 0 10e-4]); legend({'R = 1 k\Omega', 'R = 5 k\Omega', 'R = 10 k\Omega'}, 'Location', 'northeast'); figure(2),hold on,grid on;;
vtn= subs(V-vt,[R C V],[1e3 1e-6 1]); h4 = ezplot(vtn, [0 0.05]); vtn= subs(V-vt,[R C V],[5e3 1e-6 1]); h5 = ezplot(vtn, [0 0.05]); vtn= subs(V-vt,[R C V],[10e3 1e-6 1]); h6 = ezplot(vtn, [0 0.05]); xlabel('Time (s)'); ylabel('Voltage (V)'); title('Do thi Vr'); set(h4, 'LineWidth', 3, 'LineStyle', '-'); set(h5, 'LineWidth', 3, 'LineStyle', '--'); set(h6, 'LineWidth', 3, 'LineStyle', ':'); axis([0 0.05 0 1.1]); legend({'R = 1 k\Omega', 'R = 5 k\Omega', 'R = 10 k\Omega'}, 'Location', 'northeast'); figure(3),hold on,grid on;; vtn= subs(vt,[R C V],[1e3 1e-6 1]); h7 = ezplot(vtn, [0 0.05]); vtn= subs(vt,[R C V],[5e3 1e-6 1]); h8 = ezplot(vtn, [0 0.05]); vtn= subs(vt,[R C V],[10e3 1e-6 1]);; h9 = ezplot(vtn, [0 0.05]); xlabel('Time (s)'); ylabel('Voltage (V)'); title('Do thi Vc'); set(h7, 'LineWidth', 3, 'LineStyle', '-');
set(h1, 'LineWidth', 3, 'LineStyle', '-'); set(h2, 'LineWidth', 3, 'LineStyle', '--'); set(h3, 'LineWidth', 3, 'LineStyle', ':'); legend({'R = 10 Omega', 'R = 50 Omega', 'R = 100 Omega'}); axis([0 0.05 0 10.5]); b clear all, close all, syms i(t) V R C t R = input(Nhap gia tri cho R (Ohms): '); C = 1e-6; V = heaviside(t)-heaviside(t-2e-3)+heaviside(t-4e-3)- heaviside(t-6e- 3)+heaviside(t-8e-3)-heaviside(t-10e-3); eq = (R * C) * diff(i, t) + i - C*diff(V, t); sol = dsolve(eq, i(0) == 0); vr = sol * R; vc = V - vr; disp('Current (i):'); disp(sol); disp('Voltage across R (vr):'); disp(vr); disp('Voltage across C (vc):');
disp(vc); figure(1),hold on,grid on;; h1 = ezplot(vr, [0 0.01]); h2 = ezplot(vc, [0 0.01]); vt = ezplot(V, [0 0.01]); xlabel('Time (s)'); ylabel('Voltage (V)'); title('Voltage across Resistor and Capacitor'); set(h1, 'LineWidth', 2, 'LineStyle', '-'); set(h2, 'LineWidth', 2, 'LineStyle', '--'); set(vt, 'LineWidth', 2, 'LineStyle', ':', 'Color', 'r'); legend('Voltage across R (vr)', 'Voltage across C (vc)', 'Input Voltage (V)'); axis([0 0.01 -2 2]); figure(2),grid on; h = ezplot(sol, [0 0.01]); xlabel('Time (s)'); ylabel('Current (A)'); title('Current in RC Circuit'); set(h, 'LineWidth', 2); legend('Current (i)'); b clear all, close all, syms i(t) V R L it itn Vc(t) Vct C eq = diff(Vc, t, 2) + R/L * diff(Vc, t) + 1/(LC) * Vc == 1/(LC)*V;
b syms IL IR IC V(t) i t k Vt i = 0.2 * exp(-1000 * t); R = 250; L = 4e-3; C = 1e-6; eq = Cdiff(V, t, 2) + 1/R * diff(V, t) + 1/L * V == diff(i, t); Vt = dsolve(eq, V(0) == 0, subs(diff(V, t), t, 0) == 0.21e6); IL = (1/L) * int(Vt, t, 0, k); IR = Vt / R; IC = C * diff(Vt, t); disp(Vt); figure(1); grid on; hold on; h = ezplot(Vt, [0, 3e-3]); xlabel('Time (s)'); ylabel('Voltage(V)'); title('Voltage across the Circuit'); set(h, 'LineWidth', 2, 'LineStyle', '-'); axis([0 3e-3 -10 10]);
figure(2); subplot(2,2,1), grid on, hold on, h1 = ezplot(IL, [0, 3e-3]); xlabel('Time (s)'); ylabel('Current (A)') title('IL'); subplot(2,2,2), grid on, hold on, h2 = ezplot(IR, [0, 3e-3]); xlabel('Time (s)'); ylabel('Current (A)') title('IR'); subplot(2,2,3), grid on, hold on, h3 = ezplot(IC, [0, 3e-3]); xlabel('Time (s)'); ylabel('Current (A)') title('IC'); subplot(2,2,4), grid on, hold on, h4 = ezplot(i, [0, 3e-3]); xlabel('Time (s)'); ylabel('Current (A)') title('I');