Trying to graph a certain number of periods of a sine function

3 次查看(过去 30 天)
I'm developing a GUI that allows the user to input the specifications of a wave function (amplitude, etc). I have set it up to graph the function and its two derivatives on axes within the GUI. I would like the user to be able to specify the number of periods for each graph -- not the upper and lower bounds, but the total number of periods and then ideally the graph would adjust the upper and lower bounds to display the correct number of periods for each graph. Is this possible/ how would I go about adding this?

回答(1 个)

Voss
Voss 2022-12-9
A= 2; % amplitude = 2
f = 10; % frequency = 10 Hz (a.k.a. 10 cycles per second)
N = 4; % number of periods = 4 (a.k.a. 4 cycles)
t_max = N/f; % N cycles / f cycles per second = N/f seconds <- time required for N cycles at frequency f
t = linspace(0,t_max,1000);
x = A*sin(2*pi*f*t);
plot(t,x)
You can use t = 0 as the left x-limit, then the right x-limit is t_max = N/f as given above. Set the x-limits in your GUI like:
set(ax,'XLim',[0 t_max])
where ax is your axes.

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by