I'am trying to construct a function that will work like Coefficient
as an exercise.
meuCoefficient1 // ClearAll
meuCoefficient1[_?NumericQ, x_Symbol] := 0
meuCoefficient1[(a_: 1)*x_Symbol + (b_: 0), x_Symbol] := a
meuCoefficient1[(a_: 1)*y_Symbol + (b_: 0), x_Symbol] := 0
meuCoefficient1[y_Symbol, x_Symbol] := 0
meuCoefficient1[y_Symbol + n_?NumericQ, x_Symbol] := 0
For the most cases my new function (meuCoefficient
) works very well, except for the case when I have meuCoefficient[a*x + x,x]
. In this case the solution has to be a+1
, but my function is not defined for this case.
How should I extend my definition?