"Error using plot, Value not a numeric scalar"

조회 수: 32 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by