Help clearing up "Unrecognized function or variable 'dt'."

10 ビュー (過去 30 日間)
Natalie Spalding
Natalie Spalding 2021 年 2 月 27 日
コメント済み: Jan 2021 年 2 月 27 日
%% Problem 2 Linear Actuator
t0=0;
tf=0.1;
ft=0.001;
tspan=[t0:dt:tf]; %This is where I'm getting the error "Error in ProgramName(line 49)tspan=[t0:dt:tf];Unrecognized function or variable 'dt'."
x0=0;
xdot0=0;
i0=0;
IC=[x0 xdot0 0];
[t,z]=ode45(@actuator_ode,tspan,IC,[]);
x=z(:,1);
curr=z(:,3);
subplot(2,1,1)
plot(t,curr)
subplot(2,1,2)
plot(t,x)

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 2 月 27 日
編集済み: Cris LaPierre 2021 年 2 月 27 日
Based on the code you've shared, and the error message you are getting, you have not defined the variable dt that you are using to create tspan. You need to either replace dt with a numeric value, or first define dt.
tspan=[t0:0.1:tf];
% or
dt = 0.1;
tspan=[t0:dt:tf];
  1 件のコメント
Jan
Jan 2021 年 2 月 27 日
t0:dt:tf is a vector already. There is no need to include it in Matlab's operator [] for concatenating arrays.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by