2
$\begingroup$

I am trying to achieve the best fit for a non linear model, yet I need to ensure that certain coefficients return as positive values. I have been looking for similar questions but I have found nothing at all.

Below is my code, and I need to ensure that "G, F and J" return as positive values, which doesn't happen for "G".

ClearAll[A, B, F, G, H, J, P, rb, nh, f, rp, mw, eff]

FIRL = Import[
   "C:\\Users\\Utilizador\\Desktop\\TESE\\EXCELmathematica\\\
EffMathAdi - DEEPER - M2 - ATTEMPT BOTH MASSES SEMBP750W.xlsx"];



(*CASO - 2x --------------------------------------------------------------------------------------------------------------*)

nlm = NonlinearModelFit[
  FIRL[[1]], {( (P)^A*(rb)^B*(nh)^F*(rp)^G*(1 + f)^H*(mw)^
      J)*100}, {{A, 0.00000001}, {B, 0.00000001}, {F, 0.00000001}, {G,
     0.00000001}, {H, 0.00000001}, {J, 0.00000001}}, {P, rb, nh, f, 
   rp, mw}, Method -> {"Automatic"}]

nlm["ParameterConfidenceIntervalTable"]
nlm[{"ParameterTable", "RSquared"}]

(*DRL2=DRL2/.\[VeryThinSpace]Extract [nlm["BestFitParameters"],{1}];*)


A = A /. Extract [nlm["BestFitParameters"], {1}];
B = B /. Extract [nlm["BestFitParameters"], {2}];
F = F /. Extract [nlm["BestFitParameters"], {3}];
G = G /. Extract [nlm["BestFitParameters"], {4}];
H = H /. Extract [nlm["BestFitParameters"], {5}];
J = J /. Extract [nlm["BestFitParameters"], {6}];

FI = Table[{FIRL[[1, i, 7]], (FIRL[[1, i, 1]])^A*(FIRL[[1, i, 2]])^
     B*(FIRL[[1, i, 3]])^F*(FIRL[[1, i, 5]])^G*(1 + FIRL[[1, i, 4]])^
     H*(FIRL[[1, i, 6]])^J*100}, {i, 1, Dimensions[FIRL][[2]]}];

FP = Table[{FIRL[[1, i, 7]], FIRL[[1, i, 7]]}, {i, 1, 
    Dimensions[FIRL][[2]]}];

Thanks for taking the time to consider my question, I am praying for a simple command that forces the constrain...

$\endgroup$
2
  • 5
    $\begingroup$ You can literally write {( (P)^A*(rb)^B*(nh)^F*(rp)^G*(1 + f)^H*(mw)^ J)*100,G>0&&F>0&&J>0} as your model specification (or any other constraint you want to which is consistent with your starting values). (Also btw, /. can work on multiple variable at once, you dont have to Extract it for every single one). $\endgroup$ Commented Apr 29, 2022 at 16:10
  • $\begingroup$ Hey Julien! Thanks a lot...best advice ever! It works perfectly. $\endgroup$
    – Eduardo
    Commented May 3, 2022 at 8:38

0

Your Answer

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

Browse other questions tagged or ask your own question.