如何在matlab中绘制该函数的图形?
我有以下2n*π
-周期函数F(x) = sin(x/n)
,我需要绘制dx/dt = γ - F(x)
位于从 0
到 2pi
的段上。所以它应该看起来像这个。我尝试用这种方式做matlab:
gamma = 1.01;
n=3;
[t,phi] = ode45(@(t,x)gamma-sin(x/n), [0,400], pi);
[t1,phi1] = ode45(@(t,x)gamma-sin(x/n), [112,400], 0);
[t2,phi2] = ode45(@(t,x)gamma-sin(x/n), [231,250], 0);
figure();
plot(t, phi, 'k', t1, phi1, 'k', t2, phi2, 'k');
ylim([0 2*pi]);
yticks([0 pi 2*pi]);
yticklabels(["0" "\pi" "2\pi"]);
grid on; grid minor;
title('\itsin(x/n)')
但我只得到类似的东西。因此,这些行没有转移,而是“重新开始”。这里有人知道该怎么做吗?
I have the following 2n*π
-periodic function F(x) = sin(x/n)
and I need to graph the dx/dt = γ - F(x)
on the segment from 0
to 2pi
. So it should look like this. I tried to do it matlab this way:
gamma = 1.01;
n=3;
[t,phi] = ode45(@(t,x)gamma-sin(x/n), [0,400], pi);
[t1,phi1] = ode45(@(t,x)gamma-sin(x/n), [112,400], 0);
[t2,phi2] = ode45(@(t,x)gamma-sin(x/n), [231,250], 0);
figure();
plot(t, phi, 'k', t1, phi1, 'k', t2, phi2, 'k');
ylim([0 2*pi]);
yticks([0 pi 2*pi]);
yticklabels(["0" "\pi" "2\pi"]);
grid on; grid minor;
title('\itsin(x/n)')
but I only got something like this. So there the lines are not transferred, but "begin anew". does anyone here know how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到一个类似于您的第一个草图的图,并根据您在评论中的代码(将来,将此类添加内容放入问题本身,使用格式将其标记为添加,然后在评论中引用它)并
pi
作为图中所示的初始点,[0, 200]
获得与绘图相同的特征。要获得更详细的信息,请使用事件获取数值解上恰好与
2*pi
周期相交的点,然后使用它来分割解图(样式省略)I get a plot similar to your first sketch, and based on your code in the comments (in future, put such additions into the question itself, use formatting to mark it as addition, and cite it then in the comment) with the changes
pi
as initial point as seen in the drawing,[0, 200]
to get the same features as the drawing.To get more elaborate, use events to get points on the numerical solution where it exactly crosses the
2*pi
periods, then use that to segment the solution plot (styling left out)