我有這個信號:
x(t) = t*sin(m*pi*t)*heaviside(-m*pi-t) t*cos(k*pi*t)*heaviside(t-k*pi) sin(k*pi*t)*cos(m*pi*t)*(heaviside(t m*pi)-heaviside(t-k*pi));
我想使用 Matlab 計算從 -5pi 到 5pi 的值,步長為 pi/100。我怎么能做到?
uj5u.com熱心網友回復:
如果您已經在某個地方定義了,m并且k您擁有提供多載函式的matlab 符號工具箱,那么它就是這樣完成的:
% First we define the function
x = @(t) t*sin(m*pi*t)*heaviside(-m*pi-t) t*cos(k*pi*t)*heaviside(t-k*pi) sin(k*pi*t)*cos(m*pi*t)*(heaviside(t m*pi)-heaviside(t-k*pi));
% Then we define the values for which we want to compute the function
t_values = -5*pi:pi/100:5*pi;
% Finally we evaluate the function
x_values = x(t_values)
細節
第一行我們將您的函式定義為匿名函式,這是 matlab 中的一個方便工具。
然后我們創建一個從 -5pi 到 5*pi 的值向量,步長為 pi/100。為此,我們使用matlab 冒號語法。它使它簡短而高效。
最后,我們
t_values通過將向量傳遞給匿名函式來評估每個函式上的函式。
注意:如果您沒有符號工具箱,您可以輕松實作heaviside自己。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/479874.html
標籤:matlab
