function f=fkrit(a,y_orig)
load_system('model');

set_param('model/PMSM1','J',mat2str(a(1)));
set_param('model/PMSM1','F',mat2str(a(2)));

weightId = 50;
weightIq = 50;

sim('model');
f = (weightId*(Id_model-(y_orig(:,1)))' * (Id_model-(y_orig(:,1))) + ...
    weightIq*(Iq_model-(y_orig(:,2)))' * (Iq_model-(y_orig(:,2))) + ...
    (w_r_model-(y_orig(:,3)))' * (w_r_model-(y_orig(:,3))))/609;
