plotting y-axis issue and wrong plot

2 ビュー (過去 30 日間)
Faisal Al-Wazir
Faisal Al-Wazir 2022 年 10 月 19 日
回答済み: VBBV 2022 年 10 月 21 日
hi i'm writing a code for newton's 2nd law were very the mass
the first plot is Mass VS Acc
2ND Force VS Acc
3RD Force VS Mass
but i'm thinking i'm doing something wrong especially in the last plot because it look like the first one+ my axies are a bit wrong too so can anyone explain
clear
clc
subplot(3,1,1)
hold on
for m=0:100:1000
a=linspace(20,220,1000);
f=m.*a;
plot(f)
title('mass V/s Acceleration');
xlabel('acceleration');
ylabel('mass')
end
legend m=0 m=100 m=200 m=300 m=400 m=500 m=600 m=700 m=800 m=900 m=1000
subplot(3,1,2)
hold on
for m=0:100:1000
a=linspace(20,220,1000);
f=m.*a;
plot(a,f)
title('Force V/s acceleration');
xlabel('acceleration');
ylabel('Force')
end
legend m=0 m=100 m=200 m=300 m=400 m=500 m=600 m=700 m=800 m=900 m=1000
subplot(3,1,3)
hold on
for m=linspace(0,1000,11)
a=linspace(20,220,1000);
M=linspace(0,1000,1000);
f=m.*a;
plot(M,f)
title('Force V/s Mass');
xlabel('mass');
ylabel('Force')
end
legend m=0 m=100 m=200 m=300 m=400 m=500 m=600 m=700 m=800 m=900 m=1000

採用された回答

VBBV
VBBV 2022 年 10 月 21 日
subplot(3,1,3)
hold on
for m=linspace(0,1000,11)
  a=linspace(20,220,1000);
  M=linspace(0,1000,1000);
  f=M.*a;. % use M 
  plot(M,f)
  title('Force V/s Mass');
xlabel('mass'); 
ylabel('Force')
end

If you use M instead of m you can notice the difference.

その他の回答 (1 件)

azarang asadi
azarang asadi 2022 年 10 月 19 日
your m is 0:100:1000 which is a 1*11 but your a is 1*1000. It should be same size.
so m = 1:1000

カテゴリ

Help Center および File ExchangeDiscrete Events and Mode Charts についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by