Effacer les filtres
Effacer les filtres

"Error using plot, Value not a numeric scalar"

23 vues (au cours des 30 derniers jours)
Seth Antoch
Seth Antoch le 21 Déc 2020
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')

Réponses (2)

the cyclist
the cyclist le 21 Déc 2020
Modifié(e) : the cyclist le 21 Déc 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.
  1 commentaire
ozan ongun deniz
ozan ongun deniz le 11 Jan 2022
You are a miracle. Thank you so much :) :)

Connectez-vous pour commenter.


Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam le 21 Déc 2020
it should be y1(i), y2(i). or y3(i)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by