Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue

조회 수: 4 (최근 30일)
My currenct script looks like this:
function m=F(x)
k11=x(1);
k12=x(2);
k13=x(3);
k14=x(4);
l=x(5);
f1(y1,y2,y3,y4,z1)=(-(z1^3)/(y3^2))*(3*(y2-y1+y3^(-1)-z1/10)^2+(1/5)*(y2-y1+y3^(-1)-(z1)/10))-y4;
f2(y1,y2,y3,y4,z1)=1/10*z1-y4;
f3(y1,y2,y3,y4,z1)=(z1^3)*(3*(y2-y1+y3^(-1)-z1/10)^2+(1/5)*(y2-y1+y3^(-1)-(z1)/10));
f4(y1,y2,y3,y4,z1)=y1-y3^(-1);
g(y1,y2,y3,y4,z1)=(y1-y3^(-1))^2+y4^2-1/10*z1;
J1(y1,y2,y3,y4,z1)=jacobian([f1,f2,f3,f4],[y1,y2,y3,y4]);
J1=J1(2,2,1,0,10);
J2(y1,y2,y3,y4,z1)=jacobian([f1,f2,f3,f4],[z1]);
J2=J2(2,2,1,0,10);
J3(y1,y2,y3,y4,z1)=jacobian([g],[y1,y2,y3,y4]);
J3=J3(2,2,1,0,10);
J4(y1,y2,y3,y4,z1)=jacobian([g],[z1]);
J4=J4(2,2,1,0,10);
k1=[k11;k12;k13;k14];
m(1)=f1(2,2,1,0,10)+0.44*(J1(1,:)*k1 +J2(1,:)*l)-k11;
m(2)=f2(2,2,1,0,10)+0.44*(J1(2,:)*k1 +J2(2,:)*l)-k12;
m(3)=f3(2,2,1,0,10)+0.44*(J1(3,:)*k1 +J2(3,:)*l)-k13;
m(4)=f4(2,2,1,0,10)+0.44*(J1(4,:)*k1 +J2(4,:)*l)-k14;
m(5)=g(2,2,1,0,10)+0.44*(J3*k1 +J4(1,:)*l);
end
x0=[1,1,1,1,1];
fsolve(@F,x0)
Still nothing seems to get this working, can anyone help me out?
Thanks in advance.
  댓글 수: 4
Star Strider
Star Strider 2019년 4월 7일
It’s difficult to understand what you‘re doing.
However, you need to avoid using symbolic variables in the function to use as your function argument to fsolve. Use the matlabFunction function to create a numeric function fsolve can use.
Mojtaba Mohareri
Mojtaba Mohareri 2019년 4월 7일
편집: Mojtaba Mohareri 2019년 4월 7일
Actually I want to solve a system of equations with 5 unknowns k11,k12,k13,k14,l11 defined by equations m(1),...m(5). I don't know how to do that.

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

채택된 답변

Stephan
Stephan 2019년 4월 7일
Hi,
this runs - not sure if it is really efficient, but it works:
x0=[1,1,1,1,1];
fsolve(@F,x0)
function m=F(x)
syms y1 y2 y3 y4 z1 k11 k12 k13 k14 l11
h=1/1000;
f1(y1,y2,y3,y4,z1)=(-(z1^3)/(y3^2))*(3*(y2-y1+y3^(-1)-z1/10)^2+(1/5)*(y2-y1+y3^(-1)-(z1)/10))-y4;
f2(y1,y2,y3,y4,z1)=1/10*z1-y4;
f3(y1,y2,y3,y4,z1)=(z1^3)*(3*(y2-y1+y3^(-1)-z1/10)^2+(1/5)*(y2-y1+y3^(-1)-(z1)/10));
f4(y1,y2,y3,y4,z1)=y1-y3^(-1);
g(y1,y2,y3,y4,z1)=(y1-y3^(-1))^2+y4^2-1/10*z1;
J1(y1,y2,y3,y4,z1)=jacobian([f1,f2,f3,f4],[y1,y2,y3,y4]);
J1=double(J1(2,2,1,0,10));
J2(y1,y2,y3,y4,z1)=jacobian([f1,f2,f3,f4],z1);
J2=double(J2(2,2,1,0,10));
J3(y1,y2,y3,y4,z1)=jacobian(g,[y1,y2,y3,y4]);
J3=double(J3(2,2,1,0,10));
J4(y1,y2,y3,y4,z1)=jacobian(g,z1);
J4=double(J4(2,2,1,0,10));
k11=x(1);
k12=x(2);
k13=x(3);
k14=x(4);
l11=x(5);
k1=[k11;k12;k13;k14];
m(1)=double(h*(f1(2,2,1,0,10)+0.44*(J1(1,:)*k1 +J2(1,:)*l11))-k11);
m(2)=double(h*(f2(2,2,1,0,10)+0.44*(J1(2,:)*k1 +J2(2,:)*l11))-k12);
m(3)=double(h*(f3(2,2,1,0,10)+0.44*(J1(3,:)*k1 +J2(3,:)*l11))-k13);
m(4)=double(h*(f4(2,2,1,0,10)+0.44*(J1(4,:)*k1 +J2(4,:)*l11))-k14);
m(5)=double(g(2,2,1,0,10)+0.44*(J3*k1 +J4(1,:)*l11));
end
Best regards
Stephan

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by