Multiple Parameters in fmincon
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a fairly simple model that looks as follows:

I have given data for my dependent variable (y) and two covariates ('cov1' and 'cov2'). My approach so far has been the following:
% Data
y = [20, 21, 24, 26, 27, 28, 32, 37, 38, 39, 40, 45, 43, 40, 38];
cov1 = [70, 71, 74, 78, 78, 81, 83, 84, 86, 89, 91, 91, 92, 96, 91];
cov2 = [101, 101, 104, 108, 108, 110, 111, 114, 115, 117, 117, 118, 117, 119, 120];
% initial values
param_init = [0, 0, 0];
% function
y_model = @(p) p(1) + p(2).*cov1 + p(3).*cov2;
objective = @(p) sqrt(mean((y - y_model(p)).^2));
% optimization
[param_opt, fval] = fmincon(objective, param_init)
My goal is to minimize the RMSE between the observed y and my y_model values. At the moment I have specified three parameters for this purpose.
However, it would be interesting to know how I can specify that β is a p x 1 vector without specifying two separate parameters in my function ? I am not sure if this will work though?
0 commentaires
Réponses (1)
Matt J
le 19 Jan 2021
Modifié(e) : Matt J
le 19 Jan 2021
I'm not sure why you are using fmincon for something that has a simple, non-iterative solution:
C=[cov1(:).^0,cov1(:),cov2(:)];
beta = C \ y(:);
If you will eventually be adding in nonlinear (and possibly also linear) constraints, then you can set up fmincon as,
C=[cov1(:).^0,cov1(:),cov2(:)];
objective = @(p) norm(C*p(:)-y(:)).^2;
[beta_opt, fval] = fmincon(objective, beta_init,A,b,Aeq,beq,lb,ub,nonlcon);
Voir également
Catégories
En savoir plus sur Linear Least Squares dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!