这里给出一个可能的代码实现:

f[x_] := x^3 - 3 x^2 + x + 2; (* 定义一个示例函数 *)

range = {-2, 3}; (* 自变量的取值范围 *)

(* 计算函数的导数值,并判断正负和0 *) deriv = D[f[x], x]; signs = Sign[deriv /. x -> #] & /@ range; zeros = Select[range, deriv /. x -> # == 0 &];

(* 判断函数的单调性和极值点 *) monotonicity = If[deriv > 0, 'increasing', If[deriv < 0, 'decreasing', 'constant']] /. x -> # & /@ range; extremes = If[deriv' == 0 && deriv'' < 0, 'maximum', If[deriv' == 0 && deriv'' > 0, 'minimum', '']] /. x -> # & /@ zeros;

(* 构造表格 *) Grid[{{'x', Range @@ range, SpanFromLeft}, {'f'(x)', If[# > 0, '+', If[# < 0, '-', '0']] & /@ signs, SpanFromLeft}, {'f(x)', If[monotonicity[[1]] == 'increasing', FormBox[TagBox['[NearArrow]', MathMLPresentationTag, AutoDelete -> True], TraditionalForm], FormBox[TagBox['[Searrow]', MathMLPresentationTag, AutoDelete -> True], TraditionalForm]], ToString@MaxValue[{f[x], x [Element] Interval[range]}, x], If[monotonicity[[2]] == 'decreasing', FormBox[TagBox['[Nearrow]', MathMLPresentationTag, AutoDelete -> True], TraditionalForm], FormBox[TagBox['[Searrow]', MathMLPresentationTag, AutoDelete -> True], TraditionalForm]]}, {'zeros of f'(x)', If[# != {} && MemberQ[#, 0], Row[{'(', Row[#[[;; Position[#, 0][[1, 1]] - 1]], ','], Row[#[[Position[#, 0][[1, 1]] + 1 ;;]]], ')'}], Row[{'(', Row[#, ','], ')'}]] &@Split[zeros]}, {'extremes of f(x)', '', If[extremes[[1]] != '', ToString[#] <> ' (' <> extremes[[1]] <> ')' & /@ zeros, '']}}], Frame -> All, Alignment -> {Center, Center}, BaseStyle -> {FontFamily -> 'Times'}]

Mathematica代码生成函数单调性表格

原文地址: https://www.cveoy.top/t/topic/oO8j 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录