Getting an error with the ODE45 function.
Show older comments
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);
Accepted Answer
More Answers (1)
Chanae Bruno
on 15 Oct 2019
Edited: Chanae Bruno
on 15 Oct 2019
0 votes
3 Comments
James Tursa
on 15 Oct 2019
Edited: James Tursa
on 15 Oct 2019
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
on 15 Oct 2019
James Tursa
on 15 Oct 2019
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.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!