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)的结果