How do I correct undefined input argument x?
Error:
??? Input argument "x" is undefined.
Error in ==> ckt at 7
xdot(1) = x(2)/C1;
Code:
function xdot = ckt(t,x)
vg=1;
C1=100e-9;
C2=100e-9;
R=30;
L=184e-6;
xdot(1) = x(2)/C1;
xdot(2) =-(x(1) + x(3))/L + vg/L;
xdot(3) = x(2)/C2 - x(3)/(R*C2);
xdot = [xdot(1); xdot(2); xdot(3)];
t0=0; tf=60e-6;
tspan=[t0,tf];
x0=[-1 0 0]' ;
[t,x]=ode45('ckt',tspan,x0);
plot(t,x(:,3))

 채택된 답변

Star Strider
Star Strider 2021년 4월 19일

0 개 추천

Instead of using the single quotes, call the function in ode45 with a function handle as:
[t,x]=ode45(@ckt,tspan,x0);
so the full code is now:
t0=0; tf=60e-6;
tspan=[t0,tf];
x0=[-1 0 0]' ;
[t,x]=ode45(@ckt,tspan,x0);
figure
plot(t,x(:,3))
function xdot = ckt(t,x)
vg=1;
C1=100e-9;
C2=100e-9;
R=30;
L=184e-6;
xdot(1) = x(2)/C1;
xdot(2) =-(x(1) + x(3))/L + vg/L;
xdot(3) = x(2)/C2 - x(3)/(R*C2);
xdot = [xdot(1); xdot(2); xdot(3)];
t0=0; tf=60e-6;
end
And it works correctly.
See the documentation on What Is a Function Handle? for details.

댓글 수: 2

Hani Daniel
Hani Daniel 2021년 4월 19일
Thank you very much for your help.
Hani Daniel
Star Strider
Star Strider 2021년 4월 19일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

질문:

2021년 4월 19일

댓글:

2021년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by