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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by