フィルターのクリア

Problem with my matrix dimension in solving nonlinear equations

2 ビュー (過去 30 日間)
Ernest Mares
Ernest Mares 2020 年 4 月 22 日
コメント済み: Star Strider 2020 年 4 月 23 日
Hello, Im having trouble in trying to resolve a nonlinear equation for 4 unknown constants using the lsqnonline function. I have tried proofreading it but I cant seem to find the exact problem, It gives the following error.
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in workFunction (line 16)
sigma=(LAMx./LAMy).*(lx.*ly./.6)*2*a*exp((b*(E_11.^2))+(c*(E_22.^2))+(2*d*(E_11.*E_22)))*((b*E_11)+(d*E_22));
Error in Untitled2>@(C)workFunction(C,Lengths,Stress)
Error in lsqnonlin (line 206)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in Untitled2 (line 16)
Constants=lsqnonlin(@(C)workFunction(C,Lengths,Stress),x0)
Caused by:
Failure in initial objective function evaluation. LSQNONLIN cannot continue.
I created a function with the problem and the four unknown constants known as a,b,c and d which are supposed to be scalar factors.
This is the script that has the data which is 2 independent and 1 dependepent variables
Force=[0,.12,.24,.36,.48,.6,.72,1.2,1.44,1.8,2.4,3];%Newtons
str=Force/16;
Stress=reshape(str,12,1);
lx=[2;2.03;2.04;2.044;2.048;2.052;2.06;2.1;2.12;2.15;2.16;2.18];% CD mm x-direction
ly=[2;2.03;2.06;1.14;2.24;2.3;2.4;2.44;2.5;2.52;2.56;2.6];%AB distance y-direction
Lengths=[lx,ly];
disp([Lengths,Stress])
x0=[1;2;.1;1];
Constants=lsqnonlin(@(C)workFunction(C,Lengths,Stress),x0)
This is the function:
function ferror=workFunction(C,Lengths,Stress)
a=C(1);
b=C(2);
c=C(3);
d=C(4);
lx=Lengths(:,1);
ly=Lengths(:,2);
LAMx=lx./4;
LAMy=ly./4;
E_11=.5*((LAMx.^2)-1);% Strain value in x direction
E_22=.5*((LAMy.^2)-1);%Strain values in y direction
sigma=(LAMx./LAMy).*(lx.*ly./.6)*2*a*exp((b*(E_11.^2))+(c*(E_22.^2))+(2*d*(E_11.*E_22)))*((b*E_11)+(d*E_22));
ferror=Stress-sigma;

採用された回答

Star Strider
Star Strider 2020 年 4 月 22 日
When in doubt, vectorise every array operation, regarless of how distant they are from the arrays themselves (unless matrix operations are necessary).
This works:
sigma=(LAMx./LAMy).*(lx.*ly./.6).*2.*a.*exp((b*(E_11.^2))+(c*(E_22.^2))+(2*d*(E_11.*E_22))).*((b*E_11)+(d*E_22));
The solver stopped when I ran this code because it exceeded the evaluation limit. Consider using the optons structure to increase that when you run it.
.
  2 件のコメント
Ernest Mares
Ernest Mares 2020 年 4 月 22 日
Will do and Thank You!
Star Strider
Star Strider 2020 年 4 月 23 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConfigure Simulation Conditions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by