Getting Error Codes, not exactly sure what they mean or how to fix them, please help
1 view (last 30 days)
Show older comments
% Define circuit parameters
Vin_rms = 120; % V
Vout = 2.4; % V
Iload = 25e-3; % A
Vripple = 0.12; % V
R2 = 1e3; % Ohm
C = 47e-6; % F
R1 = (Vin_rms/sqrt(2) - Vout - 0.7) / 0.7 * R2; % Ohm
% Simulate circuit
tspan = [0 0.02];
opts = odeset('RelTol',1e-6);
[t,x] = ode45(@(t,x) dc_power_supply(t,x,Vin_rms,Vout,Iload,R1,R2,C), tspan, [0 0], opts);
% Plot results
figure
subplot(2,1,1)
plot(t,x(:,1))
xlabel('Time (s)')
ylabel('Voltage (V)')
title('Input Voltage')
grid on
subplot(2,1,2)
plot(t,x(:,2))
xlabel('Time (s)')
ylabel('Voltage (V)')
title('Output Voltage')
grid on
function dxdt = dc_power_supply(t,x,Vin_rms,Vout,Iload,R1,R2,C)
% Define circuit equations
dxdt(1) = sqrt(2) * Vin_rms * sin(2pi60*t) - x(1) / R1;
dxdt(2) = (x(1) / R1 - x(2) / R2 - 0.7) / (C * R2 * 2 * pi * 60) - Iload / C;
dxdt = dxdt';
end
0 Comments
Answers (1)
Torsten
on 29 Mar 2023
% Define circuit parameters
Vin_rms = 120; % V
Vout = 2.4; % V
Iload = 25e-3; % A
Vripple = 0.12; % V
R2 = 1e3; % Ohm
C = 47e-6; % F
R1 = (Vin_rms/sqrt(2) - Vout - 0.7) / 0.7 * R2; % Ohm
% Simulate circuit
tspan = [0 0.02];
opts = odeset('RelTol',1e-6);
[t,x] = ode45(@(t,x) dc_power_supply(t,x,Vin_rms,Vout,Iload,R1,R2,C), tspan, [0 0], opts);
% Plot results
figure
subplot(2,1,1)
plot(t,x(:,1))
xlabel('Time (s)')
ylabel('Voltage (V)')
title('Input Voltage')
grid on
subplot(2,1,2)
plot(t,x(:,2))
xlabel('Time (s)')
ylabel('Voltage (V)')
title('Output Voltage')
grid on
function dxdt = dc_power_supply(t,x,Vin_rms,Vout,Iload,R1,R2,C)
% Define circuit equations
dxdt(1) = sqrt(2) * Vin_rms * sin(2*pi*60*t) - x(1) / R1;
dxdt(2) = (x(1) / R1 - x(2) / R2 - 0.7) / (C * R2 * 2 * pi * 60) - Iload / C;
dxdt = dxdt';
end
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!