使い方によるエラー sym/subsindex
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
蓮 出越
el 22 de Dic. de 2022
Comentada: 蓮 出越
el 23 de Dic. de 2022
大学で自動運転に関する研究をしている者です。
サンプリングタイム0.1秒で0秒から2秒後までの次の物体の位置をすべてfigureにプロットをしたいと思っています。
ヨーレートの範囲は-10(rad/s)~10(rad/s)でサンプリングヨーレート0.1(rad/s)です。
次の時間のX座標、Y座標を求める式が下の式です。
x(t+1) = x(t) + Vcos(ω(t))dt
y(t+1) = y(t) + Vcos(ω(t))dt
ω(t) = (ヨーレート)*(サンプリングタイム)
下のコードを実行すると下のようなエラーがでるため、その原因をご教示していただければと思います。
よろしくお願いいたします。
コード
%% サンプリングタイム
sample_Ts = 10;
Ts = 1 / sample_Ts;
%% 予測ホライズン
N = 2;
%% 初期位置
% x = 0;
% y = 0;
theta0 = 0;
x = zeros(1, sample_Ts*N);
y = zeros(1, sample_Ts*N);
%% 速度
v = 10;%km/h
%% ヨーレート
% 最小ヨーレート
Yaw_min = -10;%(rad)
% 最大ヨーレート
Yaw_max = 10;%(rad)
% サンプルヨーレート
Yaw_sample = 0.1;%(rad)
% ヨーレート
%Yaw = [Yaw_min:Yaw_sample:Yaw_max];
for Yaw = Yaw_min:Yaw_sample:Yaw_max
%% 次の車両の位置
for t = 0:Ts:N
syms t;
f = v*cos(Yaw*t);
g = v*sin(Yaw*t);
x(t+Ts)=x(t)+int(f, t, t+Ts);
y(t+Ts)=y(t)+int(g, t, t+Ts);
plot(x(t),y(t))
end
end
エラー内容
使い方によるエラー sym/subsindex
インデックス付けまたは関数定義が無効です。インデックス付けは MATLAB インデックスに従わなければなりません。関数の引数はシンボリッ
ク変数でなければならず、関数本体は sym 式でなければなりません。
エラー: sample (行 35)
x(t+Ts)=x(t)+int(f, t, t+Ts);
0 comentarios
Respuesta aceptada
Atsushi Ueno
el 22 de Dic. de 2022
symsで定義したシンボリック変数 t をベクトルのインデックスに使用した事がエラーの原因です。
for文を回すならシンボリック式を使わない数値計算で事足りると思います。
%% サンプリングタイム
sample_Ts = 10;
Ts = 1 / sample_Ts;
%% 予測ホライズン
N = 2;
%% 初期位置
% x = 0;
% y = 0;
theta0 = 0;
x = zeros(1, sample_Ts*N);
y = zeros(1, sample_Ts*N);
%% 速度
v = 10;%km/h
%% ヨーレート
% 最小ヨーレート
Yaw_min = -10;%(rad)
% 最大ヨーレート
Yaw_max = 10;%(rad)
% サンプルヨーレート
Yaw_sample = 0.1;%(rad)
% ヨーレート
%Yaw = [Yaw_min:Yaw_sample:Yaw_max];
figure;
for Yaw = Yaw_min:Yaw_sample:Yaw_max
%% 次の車両の位置
index = 1;
for t = 0:Ts:N
%syms t; % シンボリック変数や式を使わず数値計算してみる
x(index) = x(max(1,index-1)) + v*(-sin(t*Yaw)+sin((t+Ts)*Yaw))/Yaw;
y(index) = y(max(1,index-1)) + v*( cos(t*Yaw)-cos((t+Ts)*Yaw))/Yaw;
plot(x(index),y(index),'*'); hold on
index = index + 1;
end
end
Más respuestas (0)
Ver también
Categorías
Más información sobre 微積分 en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!