How to curve fit using two functions in two different data segment

13 visualizaciones (últimos 30 días)
aroj bhattarai
aroj bhattarai el 7 de Abr. de 2022
Comentada: William Rose el 8 de Abr. de 2022
Dear Matlab users,
I have two set of data points, first 200 (y, x3) and second 200 (y, x1) to fit using two non-linear functions, f(x1, x2, x3) and g(x1,x2,x3). The figure is attached below.
Fitting cases: if 0.3 < x3 < 1.0, then a non-linear function f(x1,x2,x3) is to be used to fit the data. Here x1 = x2 = 1/sqrt(x3).
If 1.0 < x1,x2 < 1.7, then a combination of non-linear functions f(x1,x2,x3) + g(x1,x2,x3) is to be used, Here x1 = x2 and x3 = 1/(x1x2) and the function f(x1,x2,x3) is same in both except it takes x1 argument.
I have already fit the two data set separately using lsqcurvefit. However, how could it be possible to combine these two fitting procedure in a single Matlab fit so that f(x1, x2, x3) participates to describe both the data points between 0.3 < x < 1.7 and g(x1, x2, x3) participates only when 1.0 < x < 1.7?
Many thanks in advance.
Bhattarai
  1 comentario
Matt J
Matt J el 7 de Abr. de 2022
There is no benefit to combining the fits unless the two pieces of the function have common parameters.

Iniciar sesión para comentar.

Respuestas (1)

William Rose
William Rose el 8 de Abr. de 2022
Yes, it is possible and not too difficult. YOu just need to write the error function, or cost function, appropriately. However, the problem a yo have described it is not clear. Please post your data. Please specifiy the functions f(x,y,z) and g(x,y,z). Please be sure to distinguih clearly beteeen the independent variable and the adjustable parameters.
You said points are (y, x3), and points 201-400 are (y, x1). You also said
"a non-linear function f(x1,x2,x3) is to be used to fit the data. Here x1 = x2 = 1/sqrt(x3)"
If both of those statements are true, then there are no adjustable parameters for the f() function: x3 is the independent variable, and you cannot change it. x2 and x1 are defined in terms of x3, according to your statement, so you can;t change them either.
You said you use f() if 0<x1,x2<1.3, and want to fit it with f()+g(). And you said the x1, x2, x3 are the same But in th case of f(x1,x2,x3) there is really only one parameter, as I just described, so it is not clear what can be adjusted for g(x1,x2,x3).
You said "if 0.3 < x3 < 1.0, then a non-linear function f(x1,x2,x3) is to be used to fit the data"
and you said
"if 1.0 < x1,x2 < 1.7, then a combination of non-linear functions f(x1,x2,x3) + g(x1,x2,x3) is to be used"
If x1, x2, x3 are separetely adjustable, then you could satisfy both the first and the second conditions simultaneously. In that case, which function or functions should be used?
Please think about how you can restate the pobem more clearly. Post the specific data you want to fit. Specify the functions f() and g(). Distinguish clearly between independent variables (which you cannot adjust) and parameters (which you can adjust to fit the data).
Good luck with your work.
  4 comentarios
aroj bhattarai
aroj bhattarai el 8 de Abr. de 2022
Yes William Rose, you almost got me correctly. The data corresponds to two separate experiments: a) uniaxial compression (along direction 3) and b) biaxial tension (along direction 1 and 2) experiment of thin soft tissue and is incompressible. The sigma is the Cauchy stress and the lambda () is the stretch, but not the Green-Lagrange strain (E). The subscripts 1,2,3 refer to the different directions, 1 = length direction, 2 = width direction and 3 = thickness direction.
In the excel sheet, the six columns data are not from a single experiment, but from two separate experiments. First 4 columns are for tension and last 2 columns for the compression. I should have placed the stress-stretch data in two separate worksheet that would have been more clear without any misunderstanding.You will get complete information in the Matlab xlsread code part. Anyway, let me clarify you here.
The first four columns in the excel sheet corresponds to the biaxial tension experiment along direction 1 and 2 as:
  • 1st column: tensile stretch in direction 1
  • 2nd column: tensile Cauchy stress in direction 1
  • 3rd column: tensile stretch in direction 2
  • 4th column: tensile Cauchy stress in direction 2
  • The compresion in direction 3 is calculated in the Compression_RUN.m file using that gives the unity product of all stretches
  • The 5th and 6th columns are not related to this tension study
Secondly, the 5th and 6th column are from separate compression test and not related to the tension experiment mentioned above. The lateral stretches are computed in Tension_RUN.m file giving unity product of the stretches and zero lateral stresses.
I am glad to know that you had technical mechanics course during your undergrad studies. Please let me know if you have any other questions to understand my Matlab objective and issue.
Best regards,
Bhattarai
William Rose
William Rose el 8 de Abr. de 2022
Compression.m: This is a function. Add comments to specify the dimesions of the inputs (x, lamda) and of the output (F). x() is a vector of parameter: x=[Apar,Bpar]. The function assigns values to F(:,1) and F(:,3), but no value is assigned to F(:,2).
Compression_RUN.m. This is a script. It reads in data from spreadsheet "data.xlsx". It uses column lambda3 to compute columns 1 and 2 of array lambda, assumng incompressibility. The script creates array Esig, with column 3=sigma3 from the spreadsheet, and column 1=zeros. Column 2 of Esig is not defined, but I think it defaults to zero. The script calls lsqcurvefit() to estimate Apar and Bpar to fit the data. lsqcurvefit() calls Compression.m. Compression.m (see above) returns array F that should fit the y-data in array Esig. Array lambda (three columns) contains the x-data used for fitting. Finally, the script uses the best fit values of Apar and Bpar to compute fitted Fsig3.
Tension.m: This is a function. Add comments to specify the dimesions of the inputs (x, lamda) and of the output (F). x() is a vector of model parameters. x(1..6)=[Apar,Bpar, k1MUS,k2MUS,k1SM,k2SM], where k1 and k2 are parameters for a model of the aortic wall. The function assigns values to F(:,1) and F(:,2). No value is assigned to F(:,3). Does the final F() have two columns or three?
Tension_RUN.m: This is a script. It reads in data from spreadsheet "data.xlsx". It uses columns lambda1 and lambda 2 to compute lambda3, assuming incompressibility. The script creates array Esig, with two columns: sigma1 and sigma2 from the spreadsheet. The script calls lsqcurvefit() to estimate parameters x[1..6] to fit the stress data. lsqcurvefit() calls Tension.m. Tension.m (see above) returns array F(:,1:2) that should fit the y-data in array Esig. Array lambda (three columns) contains the x-data used for fitting. Finally, the script uses the best fit values of x[] to compute fitted Fsig1, Fsig2.
Comments:
  • Compression fits the measured sigma3, and the computed sigma1, sigma2. Tension fits the measured values sigma1, sigma2, and not the computed values sigma3. This seems like an inconsistency.
  • Compression_RUN and Tension_RUN have sections of code, after the fitting has been done, to compute the best fit values, for comparison to the measured values. I would call Tesion.m and Compression.m, with the best fit values of x, to compute the fitted values. This will assure that the fitted values that are computed will be compted the exact same way after the fit as they were computed during the fitting process. This will assure that, if you make a change in Compression.m or Tension.m, the change will automatically be taken into account when displaying the best fit estimates of stresses.
  • @aroj bhattarai, I think that you would like to fit x=[Apar,Bpar,k1MUS,k2MUS,k1SM,k2SM] all at once for the compression and the tension experiments. This is cerainly possible. You will need to write a new main script and a new funciton, which will be called by lsqcurvefit(). It is very doable. If you would like further assistance, please contact me at rosewc@udel.edu.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by