MATLAB Answers

i need solve m*d2x/dt2 + c*dx/dt + k*x= 0 with matlab and I have encountered an error Undefined function or variable 't'. please help me

19 views (last 30 days)
Thuan Huynh
Thuan Huynh on 22 Apr 2019
Edited: James Tursa on 22 Apr 2019
function dx = kc(t,x)
global cm km
dx = [-cm*x(1) - km*x(2);x(1)];
tspan = [0 15];
ic = [0 1];
global cm km
m = 20; c(1)=5; c(2)= 40; c(3) = 200; k = 20;
km=k/m;
for n = 1:3
cm = c(n)/m;
[t,x] = ode45('kc',tspan,ic);
plot(t,x(:,2)); grid;
xlabel('time - sec.');
ylabel ('displacement-m');
title('m*(d2x/dt2)+c*(dx/dt)+k*x=0; m=10 kg, k=40 N/m')
hold on
end

  0 Comments

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 22 Apr 2019
Edited: James Tursa on 22 Apr 2019
Is this code all together in one file as written above? You need to have your driver code (the code that calls ode45) first, and your derivative function code last or in another file. The ode45 function call should not be inside your derivative function.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags