Error with fittype and custom anonymous function - limit to number of indep vars?

1 view (last 30 days)
So, this works:
fittype(@(a,b,x1,x2) a*x1 + b*x2, 'independent',{'x1','x2'})
And this does not:
fittype(@(a,b,c,x1,x2,x3) a*x1 + b*x2 + c*x3, 'independent',{'x1','x2','x3'})
"Expression.... is not vaild.. has non-scalar coefficients, or cannot be evaluated..."
Why?

Answers (2)

Walter Roberson
Walter Roberson on 17 Dec 2013
Try specifying the 'independent' option, such as in the example in the documentation:
g = fittype( @(a, b, c, d, x, y) a*x.^2+b*x+c*exp(...
-(y-d).^2 ), 'independent', {'x', 'y'},...
'dependent', 'z' );
I don't think you would need to specify 'dependent'.

Charlie
Charlie on 17 Dec 2013
Did I not?
  1 Comment
Walter Roberson
Walter Roberson on 17 Dec 2013
Ah, so you did.
Sorry, the documentation is not really clear on some things, and I got confused.
Try then specifying the 'coefficients' option as well. I can't really tell if that will help, but it might.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!