Plotting for a range of values

1 view (last 30 days)
Verdan Chick
Verdan Chick on 10 Dec 2020
Answered: Geoff Hayes on 10 Dec 2020
mA = 10;
muA = 0.3;
muB = 0.1;
g = 9.81;
theta = 30;
NA = mA*g*cosd(theta);
NB = mB*g*cosd(theta);
for mB = [1:1:20]
a = ((mA)*(g)*(sind(theta)) - (muA)*(NA) + (mB)*(g)*(sind(theta)) - (muB)*(NB)) / (mA + mB)
end
plot(mB,a)
The graph is not showing a curve and the x-axis values are incorrect. Quite new to matlab, but I have used a for loop in order to gain multiple values for 'a' when mB ranges from 1-20 in increments of 1. Could anyone help?
Thank you

Answers (1)

Geoff Hayes
Geoff Hayes on 10 Dec 2020
Verdan - in your code, the mB and a are scalars whereas you want them to be arrays (for when you plot outside of the loop). Try doing
xData = 1:1:20;
a = size(xData);
for mB = xData
NB = mB*g*cosd(theta); % I moved this here since it depends upon mB
a(mB) = ((mA)*(g)*(sind(theta)) - (muA)*(NA) + (mB)*(g)*(sind(theta)) - (muB)*(NB)) / (mA + mB);
end
plot(xData,a);

Categories

Find more on Networks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!