Basic Learning of MATLAB ---------------- function differentiation

Source: Internet
Author: User
<span style="font-size:18px;">% 函数微分% 函数微分比函数积困难,积分描述函数的整体性质,微分描述函数在某一点的斜率% 由于微分非常困难,应尽量避免数值微分,特别是对实验获得的数据进行微分,这种情况下% 最好用最小二乘曲线拟合这种数据,然后对多项式进行微分% 1、使用diff()求解数值微分% diff(x)  % x为向量,所得值为[x(2)-x(1),x(3)-x(2),x(4)-x(3)...]% x是矩阵,得到矩阵的差分% x是n维数组,得到言第一个相关维的差分值% diff(x,n) % 求矩阵的n阶差分值% 如果n>size(x,dim),先计算可能的连续差分值,直到size(x,dim)=1,然后沿任意的n+1维进行差分计算% diff(x,n,dim)% 用来计算n阶差分,如果n>size(x,dim),函数返回空的数组% 实例 A=[1,3,4,5,6,88] %================================================================diff(A)          %================================================================%结果% A =%      1     3     4     5     6    88% ans =%      2     1     1     1    82B=[1,2,3;4,6,6;4,4,4]%================================================================diff(B)%================================================================%结果% B =%      1     2     3%      4     6     6%      4     4     4% ans =%      3     4     3%      0    -2    -2% 2、使用gradient求解近似梯度% 实例x=[6,9,3,4,0;5,4,1,2,5;6,7,7,8,0;7,8,9,10,0]%================================================================[fx,fy]=gradient(x)%================================================================%结果% x =%      6     9     3     4     0%      5     4     1     2     5%      6     7     7     8     0%      7     8     9    10     0% fx =%     3.0000   -1.5000   -2.5000   -1.5000   -4.0000%    -1.0000   -2.0000   -1.0000    2.0000    3.0000%     1.0000    0.5000    0.5000   -3.5000   -8.0000%     1.0000    1.0000    1.0000   -4.5000  -10.0000% fy =%    -1.0000   -5.0000   -2.0000   -2.0000    5.0000%          0   -1.0000    2.0000    2.0000         0%     1.0000    2.0000    4.0000    4.0000   -2.5000%     1.0000    1.0000    2.0000    2.0000         0% 计算规则说明% 计算规则: [Fx,Fy]=gradient(F),其中Fx为其水平方向上的梯度,Fy为其垂直方向上的梯度% Fx的第一列元素为原矩阵第二列与第一列元素之差% Fx的第二列元素为原矩阵第三列与第一列元素之差除以2% 以此类推:Fx(i,j)=(F(i,j+1)-F(i,j-1))/2。% 最后一列则为最后两列之差。% 同理,可以得到Fy。</span>

Matlab基础学习------------------函数微分

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.