代码着色html及右下角弹窗
markdown下在线代码着色,不成功
使用谷歌扩展Code Block Beautifier成功!!
<div class="dp-highlighter"><div class="bar"></div><ol start="1" class="dp-j"><li class="alt"><span><span>function [x,val,k]=grad(fun,gfun,x0) </span></span></li><li class=""><span>% 功能: 用最速下降法求解无约束问题: min f(x) </span></li><li class="alt"><span>%输入: x0是初始点, fun, gfun分别是目标函数和梯度 </span></li><li class=""><span>%输出: x, val分别是近似最优点和最优值, k是迭代次数. </span></li><li class="alt"><span>maxk=<span class="number">5000</span><span>; %最大迭代次数 </span></span></li><li class=""><span>rho=<span class="number">0.5</span><span>;sigma=</span><span class="number">0.4</span><span>; </span></span></li><li class="alt"><span>k=<span class="number">0</span><span>; epsilon=1e-</span><span class="number">5</span><span>; </span></span></li><li class=""><span><span class="keyword">while</span><span>(k<maxk) </span></span></li><li class="alt"><span> g=feval(gfun,x0); %计算梯度 </span></li><li class=""><span> d=-g; %计算搜索方向 </span></li><li class="alt"><span> <span class="keyword">if</span><span>(norm(d)<epsilon), </span><span class="keyword">break</span><span>; end </span></span></li><li class=""><span> m=<span class="number">0</span><span>; mk=</span><span class="number">0</span><span>; </span></span></li><li class="alt"><span> <span class="keyword">while</span><span>(m<</span><span class="number">20</span><span>) %Armijo搜索 </span></span></li><li class=""><span> <span class="keyword">if</span><span>(feval(fun,x0+rho^m*d)<feval(fun,x0)+sigma*rho^m*g'*d) </span></span></li><li class="alt"><span> mk=m; <span class="keyword">break</span><span>; </span></span></li><li class=""><span> end </span></li><li class="alt"><span> m=m+<span class="number">1</span><span>; </span></span></li><li class=""><span> end </span></li><li class="alt"><span> x0=x0+rho^mk*d; </span></li><li class=""><span> k=k+<span class="number">1</span><span>; </span></span></li><li class="alt"><span>end </span></li><li class=""><span>x=x0; </span></li><li class="alt"><span>val=feval(fun,x0); </span></li></ol></div>
- function [x,val,k]=grad(fun,gfun,x0)
- % 功能: 用最速下降法求解无约束问题: min f(x)
- %输入: x0是初始点, fun, gfun分别是目标函数和梯度
- %输出: x, val分别是近似最优点和最优值, k是迭代次数.
- maxk=5000; %最大迭代次数
- rho=0.5;sigma=0.4;
- k=0; epsilon=1e-5;
- while(k<maxk)
- g=feval(gfun,x0); %计算梯度
- d=-g; %计算搜索方向
- if(norm(d)<epsilon), break; end
- m=0; mk=0;
- while(m<20) %Armijo搜索
- if(feval(fun,x0+rho^m*d)<feval(fun,x0)+sigma*rho^m*g'*d)
- mk=m; break;
- end
- m=m+1;
- end
- x0=x0+rho^mk*d;
- k=k+1;
- end
- x=x0;
- val=feval(fun,x0);
谷歌扩展Code Block Beautifier的原理
A chrome extension for beautifying code blocks in any websites that contain pre
elements.
A chrome extension for highlighting codes of Medium Articles, but now, it can highlight codes in any websites that have HTML pre
'element.
因此使用在线转换后的代码,也可以加上pre来实现高亮
- function [x,val,k]=grad(fun,gfun,x0)
- % 功能: 用最速下降法求解无约束问题: min f(x)
- %输入: x0是初始点, fun, gfun分别是目标函数和梯度
- %输出: x, val分别是近似最优点和最优值, k是迭代次数.
- maxk=5000; %最大迭代次数
- rho=0.5;sigma=0.4;
- k=0; epsilon=1e-5;
- while(k<maxk)
- g=feval(gfun,x0); %计算梯度
- d=-g; %计算搜索方向
- if(norm(d)<epsilon), break; end
- m=0; mk=0;
- while(m<20) %Armijo搜索
- if(feval(fun,x0+rho^m*d)<feval(fun,x0)+sigma*rho^m*g'*d)
- mk=m; break;
- end
- m=m+1;
- end
- x0=x0+rho^mk*d;
- k=k+1;
- end
- x=x0;
- val=feval(fun,x0);
本文作者:WinterStarHu Go语言
本文链接:https://WinterStarHu.github.io/post/dai-ma-zhao-se-html/
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
本文链接:https://WinterStarHu.github.io/post/dai-ma-zhao-se-html/
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!