MATLAB: Plotting a polynomial problem

curveplotpolynomial

Trying to plot this polynomial for different values of A but no luck so far.
M=linspace(-10,10,100);
g=10;
for A=0.1:0.1:0.9
D=-(A^2-A+1/3)*(((A-1/2)*M*g-0.25*A^2)/(2*M*((A-1/2)^2+1)+0.5*(A^2-A+1/3)))-0.5*A^2
plot(M,D)
hold all
end
legend('A=0.1','A=0.2','A=0.3','A=0.4','A=0.5','A=0.6','A=0.7','A=0.8','A=0.9')

Best Answer

You forgot to use .* instead of *.
Corrected code:
workspace;
clc;
M=linspace(-10,10,100);
g=10;
lineColors = lines(9);
counter = 1;
for A=0.1:0.1:0.9
D = -(A^2-A+1/3) .* (((A-1/2)*M*g-0.25.*A^2) ./ (2*M*((A-1/2)^2+1)+0.5*(A^2-A+1/3)))-0.5*A^2
plot(M, D, 'LineWidth', 2, 'Color', lineColors(counter, :));
hold on
counter = counter + 1;
end
legend('A=0.1','A=0.2','A=0.3','A=0.4','A=0.5','A=0.6','A=0.7','A=0.8','A=0.9')
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);