1
$\begingroup$

I have a function $f(x0)=\int g(x0,x) dx$. When I plot this function vs x0, I find that f(x0) is linear in a certain range of x0, let's say, in the range [x01,x02]. I want to fit this function f to a line (A x0 + B) in the range [x01,x02]. Can anyone please tell how to do this? When I used FindFit to do this, the error was "first argument is not a rectangular array." Function f(x0) is not an array. Then it means i can't use FindFit function.

$\endgroup$

1 Answer 1

1
$\begingroup$

This can be done very simply by making a table (rectangular array) of the values. Let fn be the function that you have created using the integral. I will use

fn[x_?NumericQ] := N[Tanh[x/3]]

for the demonstration. Create the table

data = Table[{x, fn[x]}, {x, -1, 1, 1/16.}];

Carry out the fit

Fit[data, {1, x}, x]

Giving

-5.18754*10^-18 + 0.325728 x

$\endgroup$
1
  • $\begingroup$ I did exactly the same yesterday and solved the problem. But still, thanks a lot for the answer! $\endgroup$
    – cosmos
    Aug 30, 2016 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.