How to use input command "m_dot_w = input('Enter Water Mass Flowrate in (kg/s) =');" with lsqnonlin function?

1 vue (au cours des 30 derniers jours)
Hi
I consider myself Beginner with Matlab.
I am trying to solve a non-linear system of 30 to 40 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; F3; F4; F5; F6; F7; F8; F9; F10; F11; F12; F13; F14; F15; F16; F17; F18; F19; F20; F21; F22; F23; F24; F25; F26; F27; F28; F29; F30; F31; F32; F33; F34; F35; F36; F37; F38; F39; F40];
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 = [m_dot_w_initial; T_w_in_initial; m_dot_b_initial; T_b_in_initial; dT_pinch_initial; A_cond_initial; A_evap_initial; V_dot_ref_initial; Cp_w_initial; Cp_b_initial; T_b_out_initial; Q_2_initial; T_evap_initial; U_tot_evap_initial; P_2_initial; h_2_initial; T_2_K_initial; T_2_initial; s_2_initial; Rho_2_initial; T_cond_initial; U_tot_cond_initial; P_1_initial; P_ratio_initial; Eta_comp_is_initial; h_3_is_initial; h_3_initial; Eta_comp_v_initial; m_dot_r_initial; E_dot_initial; Q_1_initial; T_w_out_initial; h_4_initial; h_1_initial; T_4_K_initial; T_4_initial; dT_sub_initial; dT_sup_initial; T_3_K_initial; T_3_initial];
Lb = [m_dot_w_min; T_w_in_min; m_dot_b_min; T_b_in_min; dT_pinch_min; A_cond_min; A_evap_min; V_dot_ref_min; Cp_w_min; Cp_b_min; T_b_out_min; Q_2_min; T_evap_min; U_tot_evap_min; P_2_min; h_2_min; T_2_K_min; T_2_min; s_2_min; Rho_2_min; T_cond_min; U_tot_cond_min; P_1_min; P_ratio_min; Eta_comp_is_min; h_3_is_min; h_3_min; Eta_comp_v_min; m_dot_r_min; E_dot_min; Q_1_min; T_w_out_min; h_4_min; h_1_min; T_4_K_min; T_4_min; dT_sub_min; dT_sup_min; T_3_K_min; T_3_min];
Hb = [m_dot_w_max; T_w_in_max; m_dot_b_max; T_b_in_max; dT_pinch_max; A_cond_max; A_evap_max; V_dot_ref_max; Cp_w_max; Cp_b_max; T_b_out_max; Q_2_max; T_evap_max; U_tot_evap_max; P_2_max; h_2_max; T_2_K_max; T_2_max; s_2_max; Rho_2_max; T_cond_max; U_tot_cond_max; P_1_max; P_ratio_max; Eta_comp_is_max; h_3_is_max; h_3_max; Eta_comp_v_max; m_dot_r_max; E_dot_max; Q_1_max; T_w_out_max; h_4_max; h_1_max; T_4_K_max; T_4_max; dT_sub_max; dT_sup_max; T_3_K_max; T_3_max];
options = optimset('MaxFunEvals',5000);
fhandle = @Fault_free_HP;
[Y,resnorm,residual,exitflag] = lsqnonlin(fhandle,Y0,Lb,Hb,options);
Some of the variables (specifically the first 10 variables) I have can be made as constants an needed to be input from the user. When I included them in the equation in the function but made their upper and lower limits the same as the input value so they do not change, it did not work. When I exclude the constants and write them down as constants in the function script it works but I need the first 10 variables to be inputs that the user can input to the system when using the code. I was thinking of making a user friendly interface like GUI for example.
When I write for example: "m_dot_w = input('Enter Water Mass Flowrate in (kg/s) =');" in the function script it requires me to input the variable for every iteration!
and when I write it "m_dot_w = input('Enter Water Mass Flowrate in (kg/s) =');" in the other script the Function script does not recognize it and give an error message of "Undefined function or variable 'm_dot_w'" for instance!
I there a possible way the I can include input command with Lsqnonlin function so that the user can change these constants every time he runs the code without the need to open the code and write it down in the function script?
I would really appreciate you help!

Réponse acceptée

Jan
Jan le 2 Juin 2015
  2 commentaires
M.Abuasbeh
M.Abuasbeh le 2 Juin 2015
Thanks Jan for the prompt reply!
I am not sure if I got the idea but for example is it supposed to work like this assuming that the constant is "A", so the code will be:
A = input('Enter Water Mass Flowrate in (kg/s) =');
Y0 = [.....]; Lb = [.....]; Hb = [.....];
options = optimset('MaxFunEvals',3000);
fhandle = @Fault_free_HP_2;
[Y] = lsqnonlin(fhandle,Y0,Lb,Hb,options,A);
and then in the Function script I should write:
function F = Fault_free_HP_initial_input_2(Y,Lb,Hb,A)
T_b_out = Y(1); Q_2 = Y(2); T_evap = Y(3); U_tot_evap = Y(4); .... to unpack the rest of the variables from Y vector. Then I tried to write:
m_dot_w = A;
to use it in the equations but still did not work. It gave me the following message:
Error using All_2_Multi_Non_Linear_Equations_System_Solver Too many input arguments.
Error in lsqnonlin (line 194) initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in All_2_initial_inputs (line 44) [Y,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(fhandle,Y0,Lb,Hb,options,A);
Caused by: Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue.
M.Abuasbeh
M.Abuasbeh le 4 Juin 2015
Thanks!
I managed to fix it with an anonymous function before calling lsqnonlin function.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays 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