generate sine function with amplitude from 0 to 10 in matlab

To generate a sine function with an amplitude from 0 to 10 in MATLAB, you can use the sin function along with scaling and shifting operations. Here's an example code snippet:

main.m
% Define the range of the x-axis
x = linspace(0, 2*pi, 100); % adjust the number of points (100) for finer granularity

% Define the amplitude range
amplitude_min = 0;
amplitude_max = 10;

% Generate the sine function with the desired amplitude
amplitude = (amplitude_max - amplitude_min) / 2;
offset = amplitude_max - amplitude;
y = amplitude * sin(x) + offset;

% Plot the sine function
plot(x, y)
xlabel('Angle (radians)')
ylabel('Amplitude')
title('Sine function with amplitude from 0 to 10')
497 chars
18 lines

In this code, x represents the range of the x-axis (in this case, from 0 to 2π), and y is the generated sine function with the desired amplitude range (from 0 to 10). The amplitude variable controls the amplitude of the sine function, while the offset variable shifts the function vertically so that it starts at the desired minimum amplitude.

You can adjust the number of points in the linspace function to get a smoother or more detailed plot.

gistlibby LogSnag