plot sine function with amplitude from 0 to 10 in matlab

To plot a sine function with an amplitude from 0 to 10 in MATLAB, you can use the plot function along with the sin function. Here is an example code snippet:

main.m
% Define the amplitude range
amplitude = 0:0.1:10;

% Define the x-axis values
x = 0:0.01:2*pi;

% Initialize the figure
figure;

% Loop through each amplitude value
for a = amplitude
    % Calculate the y-values using the sine function
    y = a * sin(x);

    % Plot the sine function with the current amplitude
    plot(x, y);
    hold on;
end

% Add labels and title
xlabel('x');
ylabel('y');
title('Sine Function with Amplitude from 0 to 10');

% Add a legend to differentiate the different plots
legend(num2str(amplitude'), 'Location', 'best');

% End the hold on state
hold off;
586 chars
30 lines

This code will generate a plot with the x-axis ranging from 0 to 2*pi and the y-axis encompassing amplitudes from 0 to 10. The different amplitudes will be differentiated in the plot using a legend.

related categories

gistlibby LogSnag