Getting an error with the ODE45 function.
显示 更早的评论
Despirte my best attempts, i cannot figure out why i'm getting the ODE45 error.
This first Part of the code is in a seperate file.
function dxdt = HW4_CB(t,x) - Getting line error stating "Input argument 't' might be unused, althought a later one is used. Consider replacing it by ~."
global A b u
dxdt = A*x + b*u;
%circuit parameters%
R = 1000; % ohms
L = 0.01; %Henries
C = 1e-6; %Farads
V = 10; % Volts
t0 = 0; %define the initial time
tf = 0.001; %define the final time
A = [-1/R*C 1/C; -1/L 0];
x0= [0 0 0]; %initial conditions
b = [0 1/L];
u = 0;
[t,x] = ode45(@HW4_CB,[t0, tf], x0); This is where i'm receiveing the error.
%Plot the Capacitor Voltage%
figure(1)
plot(t,x(:,1))
xlabel('Time (sec)')
ylabel('Voltage V_C(t) (V)')
%Plot the Inductor Current%
figure(2)
plot(t,x(:,2))
xlabel('Time (sec)')
ylabel ('Current i_L(t) (A)')
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in HW4_Problem_2_CB (line 20)
[t,x] = ode45('HW4_CB',[t0, tf], x0);
采纳的回答
更多回答(1 个)
Chanae Bruno
2019-10-15
编辑:Chanae Bruno
2019-10-15
0 个投票
3 个评论
James Tursa
2019-10-15
编辑:James Tursa
2019-10-15
You are not required to use 't' in your derivative function ... that is simply a warning that can be ignored. (In fact, you are not required to use any of the input arguments, including x). Or you could use ~ as the first input argument instead of t to get rid of the warning. E.g.,
function dxdt = HW4_CB(~,x,A,b,u) % pass in A,b,u in arguments instead of global
dxdt = A*x + b*u;
return
end
Chanae Bruno
2019-10-15
James Tursa
2019-10-15
No, that is not what I meant. In general, you are not required to use any of the input arguments. But in your case, you obviouisly use x so it must remain as an input argument.
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!