plotting y-axis issue and wrong plot

3 views (last 30 days)
Faisal Al-Wazir
Faisal Al-Wazir on 19 Oct 2022
Answered: VBBV on 21 Oct 2022
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

Accepted Answer

VBBV
VBBV on 21 Oct 2022
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.

More Answers (1)

azarang asadi
azarang asadi on 19 Oct 2022
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

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!