Getting Error Codes, not exactly sure what they mean or how to fix them, please help

1 Ansicht (letzte 30 Tage)
% 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;
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
dxdt(2) = (x(1) / R1 - x(2) / R2 - 0.7) / (C * R2 * 2 * pi * 60) - Iload / C;
dxdt = dxdt';
end

Antworten (1)

Torsten
Torsten am 29 Mär. 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 Kommentare
Travis
Travis am 30 Mär. 2023
Im still getting the same error codes, not sure if maybe I'm missing a toolbox or something.
I'm copying and pasting this code exactly, this is the error code I'm getting:
Undefined function 'dc_power_supply' for input arguments of type 'double'.
Error in @(t,x)dc_power_supply(t,x,Vin_rms,Vout,Iload,R1,R2,C)
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Torsten
Torsten am 30 Mär. 2023
Bearbeitet: Torsten am 30 Mär. 2023
I don't know. You don't miss a toolbox. Maybe you mix doubles and symbolic variables somewhere somehow.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by