MATLAB: Y = X . COS(X) . SIN(X)

fplotMATLABplottingSymbolic Math Toolbox

How would I go about plotting the following equation?
Y = X .* cos(X) .* sin(X);

Best Answer

You didn't say over what range to plot x, so I'm going to assume it's from -20 to 20. Adapt as needed:
% Choose a range for x and use 500 points.
X = linspace(-20, 20, 500);
% Create Y
Y = X .* cos(X) .* sin(X);
% Plot the function.
plot(X, Y, 'b-', 'LineWidth', 2);
grid on;
xlabel('X', 'FontSize', 15);
ylabel('Y', 'FontSize', 15);
title('Y = X .* cos(X) .* sin(X)', 'FontSize', 15);
axis equal;
% Make a black line at the x and y axes
line(xlim, [0, 0], 'Color', 'k', 'LineWidth', 2);
line([0, 0], ylim, 'Color', 'k', 'LineWidth', 2);
Related Question