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?
RFunktion[a]
returnsa
whena
has a numeric value. SoRFunktion
is just the identity function. So the way you have things set up for any real numbera
you enter, you'll getTrue
fortest123[a]
. Given that, I don't see what you're trying to solve. $\endgroup$LinearModelFit
could return a symbolic result it would just returna
whenQPunkt={1,2,3}*a
andQPunkt1={1,2,3}
. So if you wantRFunktion
to return a symbolic result, it should returna
. In short for the code you've given,test123[a]
will always returnTrue
. 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$