matlab中的求导函数diff | 您所在的位置:网站首页 › diff数值大于15 › matlab中的求导函数diff |
2018-01-19 今天发现我的标题写错了,diff不知怎么写成了fill,醉醉醉 --------------------------------------------------------------------------------------------------------------- matlab中用函数diff做求导 函数描述:DIFF Difference and approximate derivative. 语法格式: Y = diff(X)Y = diff(X,n)Y = diff(X,n,dim) 1. Y = diff(X) (1). DIFF(X), for a vector X, is [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)]. X是长度为n容器,也就是长度为n的行向量,返回n-1长度的行向量,后一个数减去前一个数 >> x = [1 2 3 4 5]; >> diff(x) ans = 1 1 1 1 >> >> x=1:10; >> y=2*x; >> diff(y) ans = 2 2 2 2 2 2 2 2 2 >> 原来长度为5,结果长度为4.(2). DIFF(X), for a matrix X, is the matrix of row differences, [X(2:n,:) - X(1:n-1,:)]. X是个n行的矩阵,返回结果是n-1行的矩阵,后一行数减去前一行数 >> x = [ 1 1 1;2 2 2;4 4 4]; >> diff(x) ans = 1 1 1 2 2 2 >>(3). DIFF(X), for an N-D array X, is the difference along the firstnon-singleton dimension of X. 这个不大会,以后回了在更新吧,不过意思跟前面应该差不多。 (4).还有一种是单个点的导数值 >> syms x; >> y=power(x,2); >> y1=diff(y); >> subs(y1,x,1) ans = 2 >> y,y1 y = x^2 y1 = 2*x >> 2. Y = diff(X,n)diff(X,N) is the N-th order difference along the first non-singleton dimension (denote it by DIM). If N >= size(X,DIM), diff takes successive differences along the next non-singleton dimension. n是求导阶数 >> x=[1 1 1;2 2 2 ;4 4 4;7 7 7]; >> diff(x) ans = 1 1 1 2 2 2 3 3 3 >> diff(x,2) ans = 1 1 1 1 1 1 >> >> syms x; >> y=power(x,3); >> y1=diff(y,2); >> subs(y1,x,2) ans = 12 >> y1 y1 = 6*x >>3. diff(X,N,DIM) diff(X,N,DIM)is the Nth difference function along dimension DIM. If N >= size(X,DIM), diff returns an empty array. 求导阶数不能大于DIM >> syms x; >> y=power(x,3); >> y1=diff(y,2); >> y2=diff(y,3,2) y2 = 6*x >> y2=diff(y,3,3) y2 = 6 >> |
CopyRight 2018-2019 实验室设备网 版权所有 |