0

我有一个数据向量(名为 ydot)和一个时间向量,当我绘制 ydot 与时间的关系图时,我得到一个像正弦函数一样的周期性图形,如何计算时间平均 ydot?

以下代码计算 ydot 和时间的确切值:

T=(2*pi)/(160e6)
tspan=linspace(0,2*T,1500)
current=linspace(0,1e-6,40);
for k=1:length(current)
f = @(y, t) (current(k)/3.2911e-016)-(2.6151e+009)*sin(y)+(4.8448e+008)*sin(y+0.5697)+(5.2266e+008)*sin((160e6)*t)*cos(y);
[t{k}, y{k}] = ode45(f,tspan,2e22);
end
y1=cell2mat(y);
t1=cell2mat(t);
for k=1:length(tspan)
for j=1:length(current)
ydot(k,j)=(current(j)/3.2911e-016)-(2.6151e+009)*sin(y1(k,j))+(4.8448e+008)*sin(y1(k,j)+0.5697)+(5.2266e+008)*sin((160e6)*t1(k,j))*cos(y1(k,j));
end
end

这给出了 40 种不同电流的 ydot,以下代码将绘制特定电流(k)(其中 k=1:40)的 ydot/时间:

plot(t1(:,k),ydot(:,k))
4

2 回答 2

1

如果你的意思是一个假设的时间平均值,你可以简单地通过取 ydot 的平均值来得到这个

x = 0:0.1:10; % define time
ydot = sin(x); % get some data for ydot
average = mean(ydot); % use mean function to get time average
plot(x, ydot, x, average); % plot both, average (which should be approximately zero for this sine and ydot vs x

如果没有,您需要更清楚地指定您的任务。

于 2013-10-07T11:35:17.983 回答
0

如果时间值是等距的,lhcgeneva 的解决方案就可以了。如果没有,您只需写下适当的积分,例如通过 trapz:

time_averaged_mean = trapz(time, ydot) ./ (time(end) - time(1));
于 2013-10-07T11:40:57.603 回答