|
19 | 19 | %% -*- texinfo -*- |
20 | 20 | %% @documentencoding UTF-8 |
21 | 21 | %% @defmethod @@sym simplify (@var{x}) |
| 22 | +%% @defmethodx @@sym simplify (@var{x}, @var{y}) |
22 | 23 | %% Simplify an expression. |
23 | 24 | %% |
| 25 | +%% @var{y} can be 'special' or 'complete'. |
| 26 | +%% 'special' will simplify special function with identities. |
| 27 | +%% 'complete' will replace the identities and then simplify. |
| 28 | +%% |
24 | 29 | %% Example: |
25 | 30 | %% @example |
26 | 31 | %% @group |
|
47 | 52 | %% @end group |
48 | 53 | %% @end example |
49 | 54 | %% |
| 55 | +%% When @var{y} is 'special': |
| 56 | +%% @example |
| 57 | +%% @group |
| 58 | +%% syms x |
| 59 | +%% simplify(beta(x, 1), 'special') |
| 60 | +%% @result{} ans = (sym) |
| 61 | +%% Γ(x) |
| 62 | +%% ──────── |
| 63 | +%% Γ(x + 1) |
| 64 | +%% @end group |
| 65 | +%% @end example |
| 66 | +%% |
| 67 | +%% When @var{y} is 'complete': |
| 68 | +%% @example |
| 69 | +%% @group |
| 70 | +%% syms x |
| 71 | +%% simplify(beta(x, 1), 'complete') |
| 72 | +%% @result{} ans = (sym) |
| 73 | +%% 1 |
| 74 | +%% ─ |
| 75 | +%% x |
| 76 | +%% @end group |
| 77 | +%% @end example |
| 78 | +%% |
50 | 79 | %% @seealso{@@sym/isAlways, @@sym/factor, @@sym/expand, @@sym/rewrite} |
51 | 80 | %% @end defmethod |
52 | 81 |
|
| 82 | +%% Source: http://docs.sympy.org/dev/tutorial/simplification.html |
53 | 83 |
|
54 | | -function y = simplify(x) |
55 | | - |
56 | | - cmd = 'return sp.simplify(*_ins),'; |
| 84 | +function y = simplify(x, y) |
57 | 85 |
|
58 | | - y = python_cmd (cmd, x); |
| 86 | + if (nargin == 1) |
| 87 | + y = python_cmd('return simplify(*_ins),', x); |
| 88 | + elseif ( strcmp( y, 'special')) |
| 89 | + y = python_cmd('return expand_func(*_ins),', x); |
| 90 | + elseif ( strcmp( y, 'complete')) |
| 91 | + y = python_cmd('return simplify(expand_func(*_ins)),', x); |
| 92 | + else |
| 93 | + print_usage (); |
| 94 | + end |
59 | 95 |
|
60 | 96 | end |
61 | 97 |
|
|
66 | 102 | %! q = horner (p); |
67 | 103 | %!assert(~isequal( p - q, 0)) |
68 | 104 | %!assert(isequal( simplify(p - q), 0)) |
| 105 | + |
| 106 | +%!test |
| 107 | +%! syms x |
| 108 | +%! A = simplify(beta(x, 1), 'special'); |
| 109 | +%! B = gamma(x)/gamma(x+1); |
| 110 | +%! assert( isequal( A, B )) |
| 111 | + |
| 112 | +%!test |
| 113 | +%! syms x |
| 114 | +%! A = simplify(beta(x, 1), 'complete'); |
| 115 | +%! B = 1/x; |
| 116 | +%! assert( isequal( A, B )) |
0 commit comments