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

1 回表示 (過去 30 日間)
Travis
Travis 2023 年 3 月 29 日
編集済み: Torsten 2023 年 3 月 30 日
% 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

回答 (1 件)

Torsten
Torsten 2023 年 3 月 29 日
% 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 件のコメント
Travis
Travis 2023 年 3 月 30 日
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 2023 年 3 月 30 日
編集済み: Torsten 2023 年 3 月 30 日
I don't know. You don't miss a toolbox. Maybe you mix doubles and symbolic variables somewhere somehow.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by