Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mojtaba Mohareri
el 7 de Abr. de 2019
Comentada: Stephan
el 7 de Abr. de 2019
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 comentarios
Star Strider
el 7 de Abr. de 2019
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.
Respuesta aceptada
Stephan
el 7 de Abr. de 2019
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
2 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!