How to use input command "T_amb = input('Enter Ambient Temperature in (C) =');" with lsqnonlin function?

4 vues (au cours des 30 derniers jours)
I am a bit new to Matlab.
I am trying to solve a non-linear system of 31 equations using lsqnonlin function. I made two scripts, one for the function called "Fault_free_HP" :
function F = Fault_free_HP_initial_input(Y,Lb,Hb)
It contains all the non-linear equations and it ends with:
F =[F1; F2; .....; F31];
and the other one called "Fault_free_HP_initial_input" contains all the initial guesses of and upper and lower limits for each variable and used the fhandle tool to call the function as below:
Y0 = [.....]; Lb = [.....]; Hb = [.....];
options = optimset('MaxFunEvals',3000);
fhandle = @Fault_free_HP_2;
[Y,resnorm,residual,exitflag] = lsqnonlin(fhandle,Y0,Lb,Hb,options);
I have 10 variables that should be input by the user and then treated as constants in the code. I was thinking of making a user friendly interface like GUI for example for the user to input them.
When I use the input command "T_amb = input('Enter Ambient Temperature in (C) =');" in the function script, it ask me to input them for each single iteration, and when I tried to write the input command in the other script, the function does not recognize them and gave me an error message tell me that the variables that I input are undefined.
I there a possible way the I can include input command with Lsqnonlin function so that the user can change these constants when he runs the code without the need to open the code and write it down in the function script?
I would really appreciate your help!

Réponse acceptée

Alan Weiss
Alan Weiss le 3 Juin 2015
You need to write your script so that the values that get input become parameters that are treated as constants in the objective function. See Passing Extra Parameters for how to do this.
In short, do NOT put the piece of code asking for parameters inside your objective function. That piece of code should run first, and then you call lsqnonlin.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 commentaire
M.Abuasbeh
M.Abuasbeh le 4 Juin 2015
Thank you very much!
It finally worked ...
I used an anonymous function before calling lsqnonlin function!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Optimization Toolbox 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!

Translated by