0
$\begingroup$

Im Trying to minimize a function by varying parameter "a" with Solve or Nminimize. The Problem is that "a" is dependent on my parameter "R" which is dependent on "a" and LinearModelFit.

Here is the function for R

RFunktion[a_]:=Module[{QPunkt1,QPunkt,QundTm,lm},

QPunkt={1,2,3}*a;
QPunkt1={1,2,3};

QundTm=Transpose[{QPunkt1,QPunkt}];
lm=LinearModelFit[QundTm,x,x];

Return[lm["BestFitParameters"][[2]]]
]

And here the one I want to minimize by varying the value of "a"

    test123[a_]:=Module[{R},
   R=RFunktion[a];
   a^2-R^2==0
   ]

Now when I want to solve the equation with Solve[test123[a],a] I will get an error message, cause LinearModelFit wont recognize "a" as a number. Can I maybe give "a" an initial value or any other way to fix my problem?

$\endgroup$
3
  • $\begingroup$ RFunktion[a] returns a when a has a numeric value. So RFunktion is just the identity function. So the way you have things set up for any real number a you enter, you'll get True for test123[a]. Given that, I don't see what you're trying to solve. $\endgroup$
    – JimB
    Commented Dec 4, 2023 at 21:41
  • $\begingroup$ "a" is a function depending on "R" and "R" is a function depending on "a". That being said, LinearModelFit wont work, cause "a" isnt given as a numeric value by Solve. Im trying to solve "a^2-R^2==0", so i want to find the value of "a" for which the equation is true $\endgroup$ Commented Dec 5, 2023 at 7:05
  • $\begingroup$ If LinearModelFit could return a symbolic result it would just return a when QPunkt={1,2,3}*a and QPunkt1={1,2,3}. So if you want RFunktion to return a symbolic result, it should return a. In short for the code you've given, test123[a] will always return True. Maybe you've only given a simple example and your real example is a more complicated function. If so, you need to give something closer to the real function if not the real function itself. $\endgroup$
    – JimB
    Commented Dec 5, 2023 at 17:14

0