如何计算向量的不定积分并绘制它
How to do a indefinite integral of a vector and plot it
我是 Matlab 的新手,想积分分段积分向量。
我用来创建向量的代码如下所示:
dt=1/1000;
t=0:dt:6;
g(t<=0)=0;
g(t>=0 & t<=1)=1*t(t>=0 & t<=1);
g(t>=1 & t<=3)=1;
g(t>=3 & t<=4)=-1*(t(t>=3 & t<=4)-4);
g(t>=4)=0;
我设法通过 diff()
操作让它工作:
function [h] = diff_plot(g,t)
dt = 1/1000;
h = diff(g)*1/dt;
h(end) = h(end-1);
subplot(2,1,1);
plot(t,g);
grid on;
xlabel('Zeit in T');
title('g(t)');
subplot(2,1,2);
plot(t,h);
grid on;
xlabel('Zeit in T');
title('h(t)=dg(t)/dt');
end
但现在我不知道如何使用 int()
- 功能。我总是收到错误 "Undefined function 'int' for input arguments of type 'double'."
您可以以 diff 函数的相反方式使用 cumsum。
下面是cumsum函数的说明。
B = cumsum(A) returns the cumulative sum of A starting at the
beginning of the first array dimension in A whose size does not equal
1.
通过乘以dt,可以计算离散函数的积分。
int_g=cumsum(g)*dt;
plot(t,int_g)
我是 Matlab 的新手,想积分分段积分向量。
我用来创建向量的代码如下所示:
dt=1/1000;
t=0:dt:6;
g(t<=0)=0;
g(t>=0 & t<=1)=1*t(t>=0 & t<=1);
g(t>=1 & t<=3)=1;
g(t>=3 & t<=4)=-1*(t(t>=3 & t<=4)-4);
g(t>=4)=0;
我设法通过 diff()
操作让它工作:
function [h] = diff_plot(g,t)
dt = 1/1000;
h = diff(g)*1/dt;
h(end) = h(end-1);
subplot(2,1,1);
plot(t,g);
grid on;
xlabel('Zeit in T');
title('g(t)');
subplot(2,1,2);
plot(t,h);
grid on;
xlabel('Zeit in T');
title('h(t)=dg(t)/dt');
end
但现在我不知道如何使用 int()
- 功能。我总是收到错误 "Undefined function 'int' for input arguments of type 'double'."
您可以以 diff 函数的相反方式使用 cumsum。
下面是cumsum函数的说明。
B = cumsum(A) returns the cumulative sum of A starting at the beginning of the first array dimension in A whose size does not equal 1.
通过乘以dt,可以计算离散函数的积分。
int_g=cumsum(g)*dt;
plot(t,int_g)