我正在尝试求
cos(x/8)*sin(x)
的导数和积分。从数学上讲,我知道 f(x) 应该从 0 开始,f'(x) 应该从 1 开始。但是,我在 Matlab 中的绘图并没有显示这一点。
我尝试重新排列方程并设置上限和下限。
clc;clear;
syms x f(x) %declaring my symbolic variable
f(x)=cos(x/8)*sin(x);
dfdx=diff(f(x));
ind_ing=int(f(x));
fplot(f(x));
hold on;
fplot(dfdx);
fplot(ind_ing);
hold off
积分计算 int(f(x)) 和 ind_ing 的绘图可能不是您所期望的。函数的积分应该是 x 的函数,而不是单个值。
clc;
clear;
syms x;
f = cos(x/8) * sin(x);
dfdx = diff(f);
% Calculate the indefinite integral
F = int(f);
% Plot the function, its derivative, and the indefinite integral
fplot(f, [-20, 20]);
hold on;
fplot(dfdx, [-20, 20]);
fplot(F, [-20, 20]);
hold off;
legend('f(x)', "f'(x)", "Indefinite Integral");
title('Plot of f(x), f''(x), and the Indefinite Integral');
我们计算不定积分 F,然后将其绘制在与原始函数及其导数相同的范围内。这应该会给你一个显示预期行为的图,其中积分从 0 开始,导数从 1 开始。