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

1 view (last 30 days)
% 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

Answers (1)

Torsten
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
Travis
Travis on 30 Mar 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 on 30 Mar 2023
Edited: Torsten on 30 Mar 2023
I don't know. You don't miss a toolbox. Maybe you mix doubles and symbolic variables somewhere somehow.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!