The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# Tag Info

0

I have already answered on the main issue for your follow-up question. Here I wish to note that your data have non-positive values for the ordinate, while the function is positive in the given data range 0 < x < 1: fun[r_Real, l_Real] := Sum[a[1/r, l]^n, {n, 1, NNfun[r, l] + 1}] Show[Plot[fun[x, .3], {x, 0, 1}], ListPlot[data], PlotRange -> All] ...

2

You should define your objective function using the "black box" pattern in order to prevent symbolic processing by NonlinearModelFit: fun[r_?NumericQ, l_?NumericQ] :=Sum[a[1/r, l]^n, {n, 1, NNfun[r,l]+1}] Actually such questions were asked already many times on this site, see this FAQ answer: What are the most common pitfalls awaiting new users? This ...

7

Here is a differential equations/operator approach, leading to mathematics-based solutions instead of expression-matching ones. As the OP observes, matching algebraic expressions with expression patterns can be tricky, despite Mathematica's Optional patterns and Default values. For trigonometric functions it is usually trickier since, as @alx observes, ...

4

You can use TrigReduce to come to form with multiple angles instead of powers and then use MatchQ to compare the result with Sin[...] pattern. I also use here Inactive[Sin] to keep results of conversion Cos terms to corresponding Sin terms: MatchQ[(TrigReduce[expr]//Expand)/.{Sin[x_] -> Inactive[Sin][x], Cos[x_] -> Inactive[Sin][x + \[Pi]/2]}, a_. ...

0

If you only intend to check the identity a simple workaround might be NMinimize[NIntegrate[(a Sin[b x + c] + d - Cos[x]^2)^2, {x, 0, 2 Pi}], {a, b,c, d}] (*{9.22063*10^-15, {a -> -0.5, b -> -2., c -> -1.5708, d -> 0.5}}*)

Top 50 recent answers are included