06-21.txt
来自「matlab基础实例源文件 matlab基础实例源文件」· 文本 代码 · 共 29 行
TXT
29 行
例6-21 使用diff函数求数值微分。
解:在命令窗口中输入如下命令,并按Enter键确认。
>> h = .002;
>> x = 0:h:pi;
>> diff(sin(x.^2))/h; %is an approximation to 2*cos(x.^2).*x
>> diff((1:10).^2)
ans =
3 5 7 9 11 13 15 17 19
>> X = [4 7 2
1 6 5]
X =
4 7 2
1 6 5
>> diff(X,1,1)
ans =
-3 -1 3
>> diff(X,1,2)
ans =
3 -5
5 -1
>> diff(X,2,2) %is the 2nd order difference along the dimension 2
ans =
-8
-6
>> diff(X,3,2) %is the empty matrix.
ans =
Empty matrix: 2-by-0
>>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?