how to use fsolve with multiple variables with unique names, not vectors
6 views (last 30 days)
I want to optimise several variables and give them unique names within the function to optimize, so I have something like this:
fun = @(x1_F, T_WA, T_F)opt(x1_F, T_WA, T_F, alpha_KW, T_D, y1_D, Re_es, nu_gD, rho_gD);
x1_F0 = 0.5; T_WA0 = 345;T_F0 = 355;
T_WAopt = fsolve(fun,x1_F0 T_F0 T_WA0);
I get an error message with this code. Is there away that I can avoid putting all variables into a vector x where I would need to call them in my optimization function opt by x(1),x(2),x(3). This would make my optimization function a bit more difficult to read.
Edited: Matt J on 1 Jan 2022
This would make my optimization function a bit more difficult to read.
There is no rule that you have to refer to your variables the same way throughout your code..You have the option of unpacking the x(i) into separate variables at the beginning of opt():
function Fval=opt(x, alpha_KW, T_D, y1_D, Re_es, nu_gD, rho_gD)
x1_F=x(1); T_WA=x(2); T_F=x(3);
%More code below