Fitting data on equation
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, i have an equation (DAR_eq) with 3 parameters (R,a,Cc) that i don't know and i have to find them. I know that the following sentences might be extremly difficult for you but please at least give it a try. I have a tank with a hole which extrude a given material under a pressure. I've made an equation (DAR_eq) to solve this problem but i can't fit my results on it. My incoming data are "mu" and "DAR"
%DATA of the FLUID (KEPSTAN 6003)
rho=1.27*1000; %density of the fluid Kg/m^3
mu=[1500 1550 1600 1650 1700 1700 1750 1800 1850 1900 1950];%viscosity of the fluid [Pa*s]
DAR=[1.702 2.013 1.391 1.133 1.071 1.024 0.930 0.677 0.631 0.556 0.495];
%MACHINE DATA
m =10; %mass in kg of the weights placed on the piston
D1 =0.02; %tank diameter
D2 =0.0005; %exit hole diameter
A1 =pi*(D1/2)^2; %tank surface
A2 =pi*(D2/2)^2; %surface exit hole
%GIVEN DATA
Ppbar=[145 155 170 195 220 220 235 260 300 350 480]; %pressure in bar
Pp=Ppbar*10000;%pressure in Pa
freq=143;%frequency
FH=(Cc/(g*A2^2));
Qa=FH+a*(rho/2)*(1/(A2^2)-1/(A1^2)); %Qa is the first coefficient of my 2 grade euation of the flux (Qa*Flux^2+Qb*Flux+Qc=0)
Qb=R*mu; %Qb is the second coefficient of my 2 grade euation of the flux (Qa*Flux^2+Qb*Flux+Qc=0)
Qc=-Pp; %Qc is the third coefficient of my 2 grade euation of the flux (Qa*Flux^2+Qb*Flux+Qc=0)
Delta=(Qb.^2)-4*Qa*Qc;
%EQUATIONS
Flux =(-Qb+sqrt(Delta))/(2*Qa);
DAR_eq=Flux/freq;
0 comentarios
Respuestas (1)
nick
el 8 de Mayo de 2024
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.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!