向前差商法求导y=sin(x)
1、新建.m文件,命名为'sin_derivation.m'
2、clear;clc;a = -5;b = 5;h = 0.1;x = a:h:b;n = length(x);y1 = sin(x);颊俄岿髭dydx = zeros(1,n-1);for k= 1:n-1 dydx(k) = (sin(x(k+1))-sin(x(k)))/h;endfigure(1)plot(x,y1)hold onplot(x(2:n),dydx(1:(n-1)))hold offlegend('sin(x)','dydx')
3、运行程序并得到y' = cos(x)的结果
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:65
阅读量:91
阅读量:25
阅读量:41
阅读量:31