"Error using plot, Value not a numeric scalar"

26 visualizaciones (últimos 30 días)
Seth Antoch
Seth Antoch el 21 de Dic. de 2020
Comentada: ozan ongun deniz el 11 de En. de 2022
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')

Respuestas (2)

the cyclist
the cyclist el 21 de Dic. de 2020
Editada: the cyclist el 21 de Dic. de 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 el 21 de Dic. de 2020
it should be y1(i), y2(i). or y3(i)

Categorías

Más información sobre Programming 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!

Translated by