matlab subs eval,【荐】MATLAB求解符号表达式数值的方法:subs函数
大家看一下這個:function [xmin,funval]=TR(fun,x0,delta0,x)
delta=delta0;
eps=1.0e-4;
n=length(x0);
x0=x0';%x0為列向量
H=eye(n);
mu=0.25;
yita=0.75;
normg=1;
while normg>eps
fx=subs(fun,x,x0);
gradfun=jacobian(fun,x);
g=subs(gradfun,x,x0);%g為行向量
normg=norm(g);
s0=x0';%s0為行向量
[s,fs]=trustP(fun,g,H,delta,x,s0);%s應該為行向量
s=s';%s變為列向量
x1=x0+s;%x1為列向量
fx1=subs(fun,x,x1);
rho=(fx-fx1)/(-fs);
if rho>yita
x0=x0+s;%x0為列向量
else
x0=x0;
end
if rho<=mu
delta=0.5*delta;
else
if rho>=yita
delta=2*delta;
else
delta=delta;
end
end
g1=subs(gradfun,x,x1);%g為行向量1
y=g1-g;%y為行向量
y=y'; %ye為列向量
dyT=y';%dyT為行向量
dsT=s';%dsT為行向量
A=s*dsT;
B=H*y*dyT*H;
a=dsT*y;
b=dyT*H*y;
H=H+A/a+B/b;
end
xmin=x0;
funval=subs(fun,x,xmin)
end
function [s,fs]=trustP(fun,g,H,delta,x,s0)
epsi=1.0e-4;
r0=8;
beta=0.5;
dxT=x';
B1=x*H*dxT;
c=g*dxT;
x0=s0;
fx=subs(fun,x,x0);
sfun=fx+c+B1;%信賴域子問題函數
N=length(x);
qfun=0;
for k=1:N
qfun=qfun+x(k)^2;
end
sqfun=sqrt(qfun);
cfun=delta-sqfun;%罰函數
tol=1;
while tol>epsi
pfun=r0*cfun;
gfun=sfun+pfun;%障礙函數
[s1,sf]=NT(gfun,x,s0)
cf=subs(cfun,x,s1);
tol=r0*cf;
r0=r0*beta;
end
s=s1;
fs=subs(fun,x,s);
end
function [s1,sf]=NT(gfun,x,s0)
eps=1.0e-4;
tol=1;
s0=s0';%s0為列向量
while tol>eps
gradf=jacobian(gfun,x)
jacf=jacobian(gradf,x)
v=subs(gradf,x)
tol=norm(v);
pv=subs(jacf,x,s0
p=-inv(pv)*v';
ss1=s0+p;
s0=ss1;
end
s1=ss1;
sf=subs(fun,x,s1);
end
這三個函數是我自己編寫的,但是運行時subs函數會報錯!有誰能幫我解決一下!
總結
以上是生活随笔為你收集整理的matlab subs eval,【荐】MATLAB求解符号表达式数值的方法:subs函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据结构习题及解析二
- 下一篇: matlab人脸追踪,求大神帮助我这个菜