How to fit two sets of x,y data with different functions but same parameters using fminsearch?

2 visualizaciones (últimos 30 días)
The code i have is as follows:
It resolves the four parameters for the first set of data, but not for the second set of data. Does anyone have any ideas how do compute this. Any would be greatly appreciated. Thank you.
lam1 = linspace(1, 1 + 0.6, length(displacement_axial))
lam1 = transpose(lam1)
dF = [strain_axial_exp_nom;stress_axial_exp_nom]
dF2 = [strain_circum_exp_nom;stress_circum_exp_nom]
IG = ones(1,4)
P = fitfun(dF, dF2, IG)
G = P(1)
gamma = P(2)
k1 = P(3)
k2 = P(4)
%gamma = P(5)
Parameter_vector = [G gamma k1 k2]
stress_fit = -(G.*(2./(3.*lam1) - (2.*lam1.^2)./3) - 4.*k1.*lam1.^2.*exp(k2.*(lam1.^2.*cos((pi.*gamma)./180).^2 + sin((pi.*gamma)./180).^2./lam1 - 1).^2).*cos((pi.*gamma)./180).^2.*(lam1.^2.*cos((pi.*gamma)./180).^2 + sin((pi.*gamma)./180).^2./lam1 - 1))./lam1
lam_circum = lam1
stress_fit_circum = -(G.*(2./(3.*lam_circum) - (2.*lam_circum.^2)./3) - 4.*k1.*lam_circum.^2.*exp(k2.*(cos((pi.*gamma)./180).^2./lam_circum + lam_circum.^2*sin((pi.*gamma)./180).^2 - 1).^2)*sin((pi.*gamma)./180).^2.*(cos((pi.*gamma)./180).^2./lam_circum + lam_circum.^2.*sin((pi.*gamma)./180).^2 - 1))./lam_circum
function P = fitfun(dF,dF_circum, IG)
strain=dF(1,:);
stress=dF(2,:);
strain2 = dF_circum(1,:);
stress2 = dF_circum(2,:);
lam1 = strain + 1
lam_circum = strain2 + 1
len_strain = length(strain)
function [ds,ds2] = fit(IG)
G = IG(1)
gamma = IG(2)
k1 = IG(3)
k2 = IG(4)
% gamma = IG(5)
f = -(G.*(2./(3.*lam1) - (2.*lam1.^2)./3) - 4.*k1.*lam1.^2.*exp(k2.*(lam1.^2.*cos((pi.*gamma)./180).^2 + sin((pi.*gamma)./180).^2./lam1 - 1).^2).*cos((pi.*gamma)./180).^2.*(lam1.^2.*cos((pi.*gamma)./180).^2 + sin((pi.*gamma)./180).^2./lam1 - 1))./lam1
f2 = -(G.*(2./(3.*lam_circum) - (2.*lam_circum.^2)./3) - 4.*k1.*lam_circum.^2.*exp(k2.*(cos((pi.*gamma)./180).^2./lam_circum + lam_circum.^2*sin((pi.*gamma)./180).^2 - 1).^2)*sin((pi.*gamma)./180).^2.*(cos((pi.*gamma)./180).^2./lam_circum + lam_circum.^2.*sin((pi.*gamma)./180).^2 - 1))./lam_circum
ds = (f - stress).^2
ds2 = (f2 - stress2).^2
ds = sum(ds)
ds2 = sum(ds2)
end
P = fminsearch(@fit, IG)
end

Respuestas (1)

Sayan
Sayan el 20 de Sept. de 2023
I understand from the issue that you are trying to find the local minima of a multioutput multivariable function "fit" using the "fminseach" MATLAB function. However, the values stored in "P" dictate the position of the local minima of "ds" only and not of "ds2". The possible reasons for the issue and the fixes are mentioned below.
  • The "fminsearch" MATLAB function solves the local minima of a single output multivariable function using the derivative-free method. When a multi-output function is passed to "fminsearch" ,it by default solves for the first output, which in this case is "ds".
  • In this case, you can find "ds" and "ds2" by declaring two separate child functions of the function "fitfun" and calling "fminsearch" twice with the two function handles corresponding to "ds" and "ds2". This is shown in the following code snippet.
function ds=fit(IG)%function to find "ds"
G = IG(1);
gamma = IG(2);
k1 = IG(3);
k2 = IG(4);
f = -(G.*(2./(3.*lam1) - (2.*lam1.^2)./3) - 4.*k1.*lam1.^2.*exp(k2.*(lam1.^2.*cos((pi.*gamma)./180).^2 + sin((pi.*gamma)./180).^2./lam1 - 1).^2).*cos((pi.*gamma)./180).^2.*(lam1.^2.*cos((pi.*gamma)./180).^2 + sin((pi.*gamma)./180).^2./lam1 - 1))./lam1;
ds = (f - stress).^2;
ds = sum(ds);
end
function ds2=fit2(IG)%function to find "ds2"
G = IG(1);
gamma = IG(2);
k1 = IG(3);
k2 = IG(4);
f2 = -(G.*(2./(3.*lam_circum) - (2.*lam_circum.^2)./3) - 4.*k1.*lam_circum.^2.*exp(k2.*(cos((pi.*gamma)./180).^2./lam_circum + lam_circum.^2*sin((pi.*gamma)./180).^2 - 1).^2)*sin((pi.*gamma)./180).^2.*(cos((pi.*gamma)./180).^2./lam_circum + lam_circum.^2.*sin((pi.*gamma)./180).^2 - 1))./lam_circum;
ds2 = (f2 - stress2).^2;
ds2 = sum(ds2);
end
%declare "P" and "Q" to find the location of local minima of "ds" and "ds2"
%respectively
P = fminsearch(@fit, IG);
Q = fminsearch(@fit2, IG);
%now use the value of "P" and "Q" for further calculations
The same issue has been addressed in the following MATLAB answer.
Further information on "fminsearch" function can be found in the following MATLAB documentation.
Hope this helps in resolving the issue.

Categorías

Más información sobre Stress and Strain en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by