24小时热门版块排行榜    

查看: 371  |  回复: 1
【奖励】 本帖被评价1次,作者fspdlh增加金币 1
当前主题已经存档。

fspdlh

金虫 (正式写手)


[资源] 【原创】三点法或五点法数值求导程序

把以下代码拷到m文件里就可以了
function y=NumDiff(X,Y,x,method_fit,point_min_ins,method_diff)
% Get the differential coefficient of data base on X and Y
% y=NumDiff(X,Y)
% y=NumDiff(X,Y,x)
% y=NumDiff(X,Y,x,method_fit)
% y=NumDiff(X,Y,x,method_fit,point_min_ins)
% y=NumDiff(X,Y,x,method_fit,point_min_ins,method_diff)
%   X Y  must be vectors of the same length,raw data
%   x    points output
%   method_fit   the method of fit,'spline' or 'pchip'
%   point_min_ins   numbers of points input to the nearest step of X
%   method_diff   3 or 5, 3 points method or 5 points method

%--------------------------------------------------------------------------
%paraments initialization
if nargin<2
    error('Not enough paraments!');
end
if nargin<3
    x=X;
end
if nargin<4
    method_fit='pchip';
end
if nargin<5
    point_min_ins=5;
end
point_min_ins=point_min_ins+1;
if nargin<6
    method_diff=5;
elseif method_diff~=3 && method_diff~=5
    error('method error');
end
[m_X n_X]=size(X);
if m_X==1 && n_X>1
    X=X';
    temp=m_X;
    m_X=n_X;
    n_X=temp;
elseif m_X>1 && n_X>1
    error('X must be a vector');
end
[m_Y n_Y]=size(Y);
if m_Y~=m_X && n_Y==m_X
    Y=Y';
elseif m_Y~=m_X && n_Y~=m_X
    error('X and Y must have the same groups of data!');
end
%--------------------------------------------------------------------------
%step
N=ceil(   (    max(X)-min(X)    )/ ...
          ( min(abs(diff(X))/point_min_ins ) )  )+1;
h=(max(X)-min(X))./(N-1);
X1=[min(X):h:max(X)]';
Y1=interp1(X,Y,X1,method_fit);
%--------------------------------------------------------------------------
%coefficient
coef=zeros(N,N);
if method_diff==5
    coef(1:2,1:5)=[-25 48 -36 16 -3;-3 -10 18 -6 1];
    coef(3:N+1:N*(N-4))=1;
    coef(N+3:N+1:N*(N-3))=-8;
    coef(3*N+3:N+1:N*(N-1))=8;
    coef(4*N+3:N+1:N*N)=-1;
    coef(N-1:N,N-4:N)=[-1 6 -18 10 3;3 -16 36 -48 25 ];
    coef=coef./12;
elseif method_diff==3
    coef(1,1:3)=[-3 4 -1];
    coef(2:N+1:N*(N-2))=-1;
    coef(2*N+2:N+1:N*N)=1;
    coef(N,N-2:N)=[1 -4 3];
    coef=coef./2;
end
%--------------------------------------------------------------------------
%output
dif=coef*Y1./h;
y=interp1(X1,dif,x,method_fit);

[ Last edited by fspdlh on 2009-4-16 at 16:41 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sunxiao

荣誉版主 (著名写手)


★★★★★ 五星级,优秀推荐

谢谢提供
2楼2009-03-20 13:46:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 fspdlh 的主题更新
☆ 无星级 ★ 一星级 ★★★ 三星级 ★★★★★ 五星级
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 投票:  有多少人是今天查系统知道结果的? +17 爱看书的可乐 2026-08-26 19/950 2026-08-31 11:46 by xiangy672
[文学芳草园] 梦想 +4 myrtle 2026-08-26 4/200 2026-08-31 08:43 by 逸域隐帆
[基金申请] 中青基了要发朋友圈吗? +6 349506619 2026-08-28 6/300 2026-08-31 08:43 by kingkocxr
[基金申请] 能否申诉? +6 echo8914667 2026-08-30 7/350 2026-08-31 08:41 by kingkocxr
[基金申请] 有没有仍没收到信息的 +7 德尚中行 2026-08-27 8/400 2026-08-30 20:52 by purplejack
[考博] 找导师 +6 yuanjiabao 2026-08-29 7/350 2026-08-30 14:40 by 生科新手
[基金申请] 麻烦专家们看看评委们的意见(F口面上) +6 gdd2018 2026-08-28 11/550 2026-08-30 08:58 by 超级无敌华子
[基金申请] 我就是申请一个面上项目而已,这评审意见是按照杰青的条件评的吧? +6 gouxfjh 2026-08-28 11/550 2026-08-30 07:57 by gouxfjh
[基金申请] 国自然面上复盘~欢迎讨论 (金币+15) +15 晴天加油 2026-08-26 16/800 2026-08-29 18:28 by symmetry
[基金申请] 怎么查啊 +6 huang1991js 2026-08-26 6/300 2026-08-28 08:42 by winsaint
[基金申请] 基金未中,这种答复是模板吗? +5 zhaosm1982 2026-08-27 6/300 2026-08-27 16:00 by lfy8008
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 怎么看青基中了没有啊 +5 叶九微 2026-08-26 5/250 2026-08-27 10:35 by l_zh2008
[基金申请] 2026年8月25日国自然放榜前突然收到列入评审专家邮件,有关系吗? +25 木水思豆 2026-08-25 28/1400 2026-08-26 14:53 by draco1987
[基金申请] 为什么国自然不能直接公布 +4 bjdxyxy 2026-08-26 4/200 2026-08-26 13:12 by qingmu1201
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 项目信息和经费信息在系统里都可以看到了 +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[基金申请] 今天务委会开完了,明天出结果吗 +19 angus9576 2026-08-25 23/1150 2026-08-26 10:03 by zp519
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
[基金申请] 某些机构,以效率低为荣,以效率低作为存在感 +9 yuleib84 2026-08-25 10/500 2026-08-25 17:14 by alexon
信息提示
请填处理意见