Optimization problem with multivariable functions

조회 수: 5 (최근 30일)
Daniel Arvidsson
Daniel Arvidsson 2018년 1월 15일
편집: Matt J 2018년 1월 15일
Hey!
I try to optimize a function with syms but get an error. Im new to syms but wanted to try and learn. The code i been written is:
% Testing_syms_functions
clc
D=1; S=1;L=1;q=1;
syms x a1 a2 b2 b3 b4
ws(x, a1, a2, b2, b3, b4) = a1*x + a2*x^2;
wb(x, a1, a2, b2, b3, b4) = b2*x^2 + b3*x^3 + b4*x^4;
dwsx=diff(ws,x,1);
d2wbx=diff(wb,x,2);
U1 = 0.5*int((D*(d2wbx)^2 + S*(dwsx)^2),0,L) ;
U2 = -int(q*(ws+wb),0,L);
E = U1 + U2;
dEa1=diff(E,a1,1);
dEa2=diff(E,a2,1);
dEb2=diff(E,b2,1);
dEb3=diff(E,b3,1);
dEb4=diff(E,b4,1);
dE=[dEa1 dEa2 dEb2 dEb3 dEb4];
H=[diff(dEa1,a1,1), diff(dEa2,a1,1), diff(dEb2,a1,1), diff(dEb3,a1,1), diff(dEb4,a1,1);
diff(dEa2,a1,1), diff(dEa2,a2,1) diff(dEb2,a2,1), diff(dEb3,a2,1), diff(dEb4,a2,1);
diff(dEb2,a1,1), diff(dEb2,a2,1), diff(dEb2,b2,1), diff(dEb2,b3,1),diff(dEb2,b4,1);
diff(dEb3,a1,1), diff(dEb3,a2,1), diff(dEb3,b2,1), diff(dEb3,b3,1), diff(dEb3,b4,1);
diff(dEb4,a1,1), diff(dEb4,a2,1), diff(dEb4,b2,1), diff(dEb4,b3,1), diff(dEb4,b4,1);];
c=[2; 1; 1; 1; 1];
kmax=10; tol=0.5e-8;
for k=1:kmax
d=-H\dE(c);
c=c+d;
disp([c' norm(d)])
if norm(d)<tol, break, end
end
Now i get an error saying:
Error using symfun/subsref (line 172)
Symbolic function expected 5 input arguments but received 1.
Error in Testing_syms_functions (line 41)
d=-H\dE(c);
Can someone please help me?
BR
Daniel
  댓글 수: 1
Torsten
Torsten 2018년 1월 15일
편집: Torsten 2018년 1월 15일
dE must be a column vector, not a row vector.
And to evaluate dE for a numerical input vector c, you will have to use the "subs" command, I guess.
Best wishes
Torsten.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Utilities for the Solver에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by