using lsqnonlin with multiple functions

조회 수: 6 (최근 30일)
joshua payne
joshua payne 2023년 4월 26일
답변: Alex Sha 2023년 8월 4일
im trying to optimize parameters,x, using 3 functions, fun1, fun2, fun3.
the optimized parameters must be the best fit for all 3 functions, not individually.
% ogden
clc
clear all
D=readmatrix('Treloar_data.xlsx');
stretch=D(1:end,1); %this is lambda
lambda=stretch;
stress=D(1:end,2); %this is stress
T_0=stress;
lambda_EBT=D(1:17,5);
T_0_EBT=D(1:17,6);
lambda_shear=D(1:14,3);
T_0_shear=D(1:14,4);
fun1=@(x)((x(1)*(lambda.^(x(4)-1) -lambda.^(-.5*x(4)-1))+x(2)*(lambda.^(x(5)-1) -lambda.^(-.5*x(5)-1))+x(3)*(lambda.^(x(6)-1) -lambda.^(-.5*x(6)-1)))-T_0);
fun2=@(x)((x(1)*(lambda_EBT.^(x(4)-1) -lambda_EBT.^((-7/2)*x(4)-(5/2)))+x(2)*(lambda_EBT.^(x(5)-1) -lambda_EBT.^((-7/2)*x(5)-(5/2)))+x(3)*(lambda_EBT.^(x(6)-1) -lambda_EBT.^((-7/2)*x(6)-(5/2))))-T_0_EBT);
fun3=@(x)((x(1)*(lambda_shear.^(x(4)-1) -lambda_shear.^((-5/2)*x(4)-(3/2)))+x(2)*(lambda_shear.^(x(5)-1) -lambda_shear.^((-5/2)*x(5)-(3/2)))+x(3)*(lambda_shear.^(x(6)-1) -lambda_shear.^((-5/2)*x(6)-(3/2))))-T_0_shear);
fun=[fun1; fun2; fun3]
% x0=[1, 1, 1, 1, 1, 1];%initial geuss is sensitive
x0=[.5649 ,(3.856*10^(-3)) 0 ,1.297, 4.342, 15.13];
x=lsqnonlin(fun,x0);
c(1)=x(1) %mu1
c(2)=x(2) %mu2
c(3)=x(3) %mu3
c(4)=x(4) %alpha1
c(5)=x(5) %alpha2
c(6)=x(6) %alpha3
T_0_ogden=(c(1)*(lambda.^(c(4)-1) -lambda.^(-.5*c(4)-1))+c(2)*(lambda.^(c(5)-1) -lambda.^(-.5*c(5)-1))+c(3)*(lambda.^(c(6)-1) -lambda.^(-.5*c(6)-1)));
T_0_ogden_EBT=(x(1)*(lambda_EBT.^(x(4)-1) -lambda_EBT.^((-7/2)*x(4)-(5/2)))+x(2)*(lambda_EBT.^(x(5)-1) -lambda_EBT.^((-7/2)*x(5)-(5/2)))+x(3)*(lambda_EBT.^(x(6)-1) -lambda_EBT.^((-7/2)*x(6)-(5/2))));
T_0_ogden_shear=(x(1)*(lambda_shear.^(x(4)-1) -lambda_shear.^((-5/2)*x(4)-(3/2)))+x(2)*(lambda_shear.^(x(5)-1) -lambda_shear.^((-5/2)*x(5)-(3/2)))+x(3)*(lambda_shear.^(x(6)-1) -lambda_shear.^((-5/2)*x(6)-(3/2))));
figure
plot(lambda,T_0,'r')
hold on
plot(lambda,T_0_ogden,'b')
plot(lambda_EBT,T_0_ogden_EBT,'g')
plot(lambda_shear,T_0_ogden_shear,'c')

답변 (2개)

Torsten
Torsten 2023년 4월 26일
이동: Torsten 2023년 4월 26일
So you want
sum(((x(1)*(lambda.^(x(4)-1) -lambda.^(-.5*x(4)-1))+x(2)*(lambda.^(x(5)-1) -lambda.^(-.5*x(5)-1))+x(3)*(lambda.^(x(6)-1) -lambda.^(-.5*x(6)-1)))-T_0).^2) +
sum((((x(1)*(lambda_EBT.^(x(4)-1) -lambda_EBT.^((-7/2)*x(4)-(5/2)))+x(2)*(lambda_EBT.^(x(5)-1) -lambda_EBT.^((-7/2)*x(5)-(5/2)))+x(3)*(lambda_EBT.^(x(6)-1) -lambda_EBT.^((-7/2)*x(6)-(5/2))))-T_0_EBT).^2) +
sum(((x(1)*(lambda_shear.^(x(4)-1) -lambda_shear.^((-5/2)*x(4)-(3/2)))+x(2)*(lambda_shear.^(x(5)-1) -lambda_shear.^((-5/2)*x(5)-(3/2)))+x(3)*(lambda_shear.^(x(6)-1) -lambda_shear.^((-5/2)*x(6)-(3/2))))-T_0_shear).^2)
to be minimzed with respect to x ?
Then define
fun = @(x)[fun1(x);fun2(x);fun3(x)];
  댓글 수: 2
joshua payne
joshua payne 2023년 4월 26일
im confused why the code has sum's around each function and then youre still calling fun1, fun2, fun3
Torsten
Torsten 2023년 4월 26일
편집: Torsten 2023년 4월 26일
The long expression with the sums over the arrays squared would not be part of the code.
I asked the question if this sum expression is the function you want to minimize with respect to x.
If this is the case, use
fun = @(x)[fun1(x);fun2(x);fun3(x)];

댓글을 달려면 로그인하십시오.


Alex Sha
Alex Sha 2023년 8월 4일
@joshua payne refer to the results below
Sum Squared Error (SSE): 0.377485784540046
Root of Mean Square Error (RMSE): 0.0821024821858161
Correlation Coef. (R): 0.996098098188982
R-Square: 0.992211421215707
Parameter Best Estimate
--------- -------------
c1 0.0323483986102822
c2 -1.23856186333989
c3 1.19422161081346E-14
c4 3.36896942510881
c5 -0.571016034599837
c6 17.1390641835716
T_0_ogde:
T_0_ogde
T_0_ogden
T_0_ogden_shear

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by