Error using plot, vectors must have the same length

2 ビュー (過去 30 日間)
Mostafa Moradi
Mostafa Moradi 2021 年 3 月 28 日
コメント済み: darova 2021 年 3 月 29 日
I get the error
error using plot
"Vectors must be the same length"
when I run this code
F= 200 ; V=10 ; Q=1 ; k=0.1 ;
t(1)= 0;
c(1)= 0;
h=0.01;
Y= @(t,c) F/V-Q.*c/V-k.*c.^2;
for i= 1:200
t(i+1)= t(i)+h;
k1= c(i);
k2= c(i)+0.5*k1*h;
k3= c(i)+0.5*k2*h;
k4= c(i)+k3*h;
c(i+1)= c(i)+h*(k1+2*k2+2*k3+k4)/6;
end
plot(t,c)
  1 件のコメント
darova
darova 2021 年 3 月 29 日
Please use code inserting button

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

回答 (1 件)

Sergio Yanez-Pagans
Sergio Yanez-Pagans 2021 年 3 月 28 日
Just check the sizes of t and c. You can check this on the variable window or on the command window as follows:
size(t) % will show dimensions for t
size(c) % will show dimensions for c
Plot requires a 1-on-1 correspondence, so for example, if t is 1x10, c MUST be 1x10
Hope you find this useful!

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by