Clear Filters
Clear Filters

"Error using plot, Value not a numeric scalar"

30 views (last 30 days)
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')

Answers (2)

the cyclist
the cyclist on 21 Dec 2020
Edited: the cyclist on 21 Dec 2020
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.

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam on 21 Dec 2020
it should be y1(i), y2(i). or y3(i)

Community Treasure Hunt

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

Start Hunting!