필터 지우기
필터 지우기

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.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Configure Simulation Conditions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by