"Error using plot, Value not a numeric scalar"

27 ビュー (過去 30 日間)
Seth Antoch
Seth Antoch 2020 年 12 月 21 日
コメント済み: ozan ongun deniz 2022 年 1 月 11 日
clc, close all
c=12.5; % kg/s drag coefficient
M=70; % kg mass
g=9.81; % m/s^2 gravity
delta_t=0.1; % s time step
t=0:delta_t:12; % s time overall
x=0:500; % m displacement
n=length(t);
for i=2:n
c1=(x(i+1)-x(i))/delta_t; % first der central
c2=(x(i+2)-2*x(i+1)+x(i))/(delta_t.^2); % second der central
y1=c2+((c./M).*c1)-g; % central difference
f1=(x(i+1)-x(i))/delta_t; % first der forward
f2=(x(i+2)-2*x(i+1)+x(i))/(delta_t.^2); % second der forward
y2=f2+((c./M).*f1)-g; % forward difference
b1=(x(i)-x(i-1))/(2*delta_t); % first der backward
b2=(x(i+1)-2*x(i)+x(i-1))/(delta_t.^2); % second der backward
y3=b2+((c./M)*b1)-g; % backward difference
end
plot(t,y1,'b','linewidth','2')
hold on
plot(t,y2,'r','linewidth','2')
hold on
plot(t,y3,'k','linewidth','2')

回答 (2 件)

the cyclist
the cyclist 2020 年 12 月 21 日
編集済み: the cyclist 2020 年 12 月 21 日
The LineWidth parameter should just be the number 2 (without quotes), not the character '2'.
After that, you are going to run into the problem that in your for loop, you are not creating a vector y1. You are instead overwriting a single scalar value of y1 in each iteration of the loop.
  1 件のコメント
ozan ongun deniz
ozan ongun deniz 2022 年 1 月 11 日
You are a miracle. Thank you so much :) :)

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


Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 12 月 21 日
it should be y1(i), y2(i). or y3(i)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by