write matlab script file to plot three related functions of x: y1 = 2 cos(x), y2 = cos(x), and y3 = 0:5 * cos(x), in the interval 0 ≤ x ≤ 2π. give xlabel, ylabel, legend, title, axis to the plot. in matlab

To plot the three related functions of x in MATLAB, you can create a script file with the following code:

main.m
% Define the range of x values
x = 0:0.1:2*pi;

% Compute the values of y1, y2, and y3
y1 = 2 * cos(x);
y2 = cos(x);
y3 = 0.5 * cos(x);

% Plot the three functions
plot(x, y1, 'r', 'LineWidth', 2);
hold on;
plot(x, y2, 'g', 'LineWidth', 2);
plot(x, y3, 'b', 'LineWidth', 2);

% Add xlabel and ylabel
xlabel('x');
ylabel('y');

% Add a legend
legend('y1 = 2 cos(x)', 'y2 = cos(x)', 'y3 = 0.5 cos(x)');

% Add a title
title('Plot of Three Related Functions of x');

% Set the axis limits
axis([0 2*pi -3 3]);

% Hold off to prevent further plotting on the same figure
hold off;
576 chars
30 lines

Save the script file with a .m extension (e.g., plot_functions.m) and run it in MATLAB. You will see a plot with three functions, x-axis label, y-axis label, legend, title, and specified axis limits.

gistlibby LogSnag