Hi Alessandro,
You can use the "lsqcurvefit" function , which solves nonlinear curve-fitting problems in least-squares sense, to estimate the parameters Cc,a,R. However, the variable g is not defined in the code snippet shared by you so I am assuming g as a parameter to be estimated.
The following code snippet highlights the changes required to use "lsqcurvefit" function :
%% Initital Guess
initialGuess = [10 1 1 1]; %Inital Guess of [Cc,g,a,R]
%%
FH=@(Cc,g,a)(Cc/(g*A2^2));
Qa=@(Cc,g,a) FH(Cc,g,a)+a*(rho/2)*(1/(A2^2)-1/(A1^2)); %Qa is the first coefficient of my 2 grade equation of the flux (Qa*Flux^2+Qb*Flux+Qc=0)
Qb=@(R) R*mu; %Qb is the second coefficient of my 2 grade equation of the flux (Qa*Flux^2+Qb*Flux+Qc=0)
Qc=-Pp; %Qc is the third coefficient of my 2 grade equation of the flux (Qa*Flux^2+Qb*Flux+Qc=0)
Delta= @(Cc,g,a,R)(Qb(R).^2)-4*Qa(Cc,g,a)*Qc;
%EQUATIONS
Flux = @(Cc,g,a,R) (-Qb(R)+sqrt(Delta(Cc,g,a,R)))/(2*Qa(Cc,g,a));
DAR_eq= @(p,x) Flux(p(1),p(2),p(3),p(4))/freq;
%Least Square Method
options = optimoptions('lsqcurvefit','Display','iter','OptimalityTolerance',1e-10, 'FunctionTolerance',1e-10); % Optional: Suppress output
[params, resnorm] = lsqcurvefit(DAR_eq, initialGuess, mu, DAR, [], [], options)
% Display the found parameters
disp('Found parameters:');
disp(params);
You may refer to the following documentation to learn more about the "lsqcurvefit" function :
Hope this helps.