-2

Consider this:

clear all
clc
close all

x = 0:0.1:10;
y = 2.*sin(x) + 0.1.*rand(1,length(x));
mdl = fitlm(x,y);
plotAdded(mdl)

The unknown parameters are the coefficients of 2sin(x), that is +1. So, the model is linear, however, "fitlm" does not work here as it tries to fit the data to a model like "a*x+b". I want it to fit the data to a model like asin(x) + b; the a and b are the unknown. How, can I fit the data to a linear combination of non-linear functions or custom functions. I need a solution that works for other functions such as Cos, Log, Exp or user defined functions.

I would like to do this fitting with statistics toolbox and programmatically.

1
  • Your question is a little unclear, but from what i get you may want to look at the documentation of lsqr or lsqlin. Jun 9, 2017 at 13:57

1 Answer 1

0

The linear model only permits linear functions. But you can do your customized functions like this:

mdl = fitlm(sin(x),y);

It looks good:

The result

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.