早教吧 育儿知识 作业答案 考试题库 百科 知识分享

在matlab中,用两种方法求函数sinx/(x+cos2x)的数值导数,并在同一个坐标系中做出f(x)的图像.

题目详情
在matlab中,用两种方法求函数sinx/(x+cos2x)的数值导数,并在同一个坐标系中做出f(x)的图像.
▼优质解答
答案和解析
做个测试,希望有所帮助.
代码
% By lyqmath
% 在matlab中,用两种方法求函数sinx/(x+cos2x)的数值导数,
% 并在同一个坐标系中做出f(x)的图像.
clc; clear all; close all;
%% 方法1
syms x
y = sin(x)/(x + cos(2*x));
dy = diff(y);
xt = linspace(0, 2*pi);
yt = subs(dy, x, xt);
%% 方法2
yt1 = diff(subs(y, x, xt));
xt1 = diff(xt);
%% 绘图
figure; hold on;
plot(xt, yt, 'r-', xt(2:end), yt1./xt1, 'k:');
结果