在matlab中实现梯度下降法1

		<div class="blogStats">
			
			<div id="blog_stats">

随笔- 145 
文章- 0 
评论- 1099 

		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->

在matlab中实现梯度下降法

梯度下降法的原理,本文不再描述,请参阅其它资料。

梯度下降法函数function [k ender]=steepest(f,x,e),需要三个参数f、x和e,其中f为目标函数,x为初始点,e为终止误差。输出也为两个参数,k表示迭代的次数,ender表示找到的最低点。

 

steepest.m:

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

 

调用示例1:

syms x1 x2;
f=(x1-2)^2+2*(x2-1)^2;
x=[1;3];
e=10^(-20);
[k ender]=steepest(f,x,e)

结果:

复制代码
k =
27

ender =

 2
 1</span></pre>
复制代码


调用示例2:

syms x1 x2;
f=x1-x2+2*x1^2+2*x1*x2+x2^2;
x=[0;0];
e=10^(-20);
[k ender]=steepest(f,x,e)

结果:

复制代码
k =
58

ender =

-1.0000
1.5000

复制代码


调用示例3:

syms x1 x2;
f=3/2*x1^2+1/2*x2^2-x1*x2-2*x1;
x=[0;0];
e=10^(-2);
[k ender]=steepest(f,x,e)


结果:

复制代码
k =
 9

ender =

0.9959
0.9877</span></pre>
复制代码

 

分类: matlab
2
0
« 上一篇: 在matlab中实现PCA算法
» 下一篇: 在matlab中实现线性回归和logistic回归
	</div>
	<div class="postDesc">posted @ <span id="post-date">2014-10-15 00:06</span> <a href="https://www.cnblogs.com/denny402/">denny402</a> 阅读(<span id="post_view_count">12786</span>) 评论(<span id="post_comment_count">2</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=4025472" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(4025472);return false;">收藏</a></div>
</div>
<script type="text/javascript">var allowComments=true,cb_blogId=72158,cb_entryId=4025472,cb_blogApp=currentBlogApp,cb_blogUserGuid='71830865-4f7c-df11-ba8f-001cf0cd104b',cb_entryCreatedDate='2014/10/15 0:06:00';loadViewCount(cb_entryId);var cb_postType=1;</script>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"></span>
			</div>
			<a href="#3187352" class="layer">#1楼</a><a name="3187352" id="comment_anchor_3187352"></a> <span class="comment_date">2015-05-19 21:02</span> | <a id="a_comment_author_3187352" href="http://home.cnblogs.com/u/427400/" target="_blank">Daniel.Tsang</a> <a href="http://msg.cnblogs.com/send/Daniel.Tsang" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3187352" class="blog_comment_body">运行提示错误:<br><br>Undefined function 'norm' for input arguments of<br>type 'sym'.<br><br>Error in steepest (line 10)<br>    nor=norm(d_temp); %范数</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3187352,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3187352,'Bury',this)">反对(0)</a></div>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"></span>
			</div>
			<a href="#3751506" class="layer">#2楼</a><a name="3751506" id="comment_anchor_3751506"></a><span id="comment-maxId" style="display:none;">3751506</span><span id="comment-maxDate" style="display:none;">2017/8/6 15:32:37</span> <span class="comment_date">2017-08-06 15:32</span> | <a id="a_comment_author_3751506" href="http://home.cnblogs.com/u/1214326/" target="_blank">∮Lakers</a> <a href="http://msg.cnblogs.com/send/%E2%88%AELakers" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3751506" class="blog_comment_body">很实用,最喜欢这种可以直接找到代码的了,代码去运行了一遍很不错的。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3751506,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3751506,'Bury',this)">反对(0)</a></div>
		</div>
	</div>
<div id="comments_pager_bottom"></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
</div><!--end: forFlow -->
</div><!--end: mainContent 主体内容容器-->

<div id="sideBar">
	<div id="sideBarMain">

公告

昵称: denny402
园龄: 8年4个月
粉丝: 1122
关注: 3
+加关注
		<div id="calendar"><div id="blog-calendar" style=""><table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="Calendar">
<tbody><tr><td colspan="7"><table class="CalTitle" cellspacing="0">
	<tbody><tr><td class="CalNextPrev"><a href="javascript:void(0);" onclick="loadBlogCalendar('2018/10/01');return false;">&lt;</a></td><td align="center">2018年11月</td><td class="CalNextPrev" align="right"><a href="javascript:void(0);" onclick="loadBlogCalendar('2018/12/01');return false;">&gt;</a></td></tr>
</tbody></table></td></tr><tr><th class="CalDayHeader" align="center" abbr="日" scope="col">日</th><th class="CalDayHeader" align="center" abbr="一" scope="col">一</th><th class="CalDayHeader" align="center" abbr="二" scope="col">二</th><th class="CalDayHeader" align="center" abbr="三" scope="col">三</th><th class="CalDayHeader" align="center" abbr="四" scope="col">四</th><th class="CalDayHeader" align="center" abbr="五" scope="col">五</th><th class="CalDayHeader" align="center" abbr="六" scope="col">六</th></tr><tr><td class="CalOtherMonthDay" align="center">28</td><td class="CalOtherMonthDay" align="center">29</td><td class="CalOtherMonthDay" align="center">30</td><td class="CalOtherMonthDay" align="center">31</td><td align="center">1</td><td align="center">2</td><td class="CalWeekendDay" align="center">3</td></tr><tr><td class="CalWeekendDay" align="center">4</td><td align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">9</td><td class="CalWeekendDay" align="center">10</td></tr><tr><td class="CalWeekendDay" align="center">11</td><td class="CalTodayDay" align="center">12</td><td align="center">13</td><td align="center">14</td><td align="center">15</td><td align="center">16</td><td class="CalWeekendDay" align="center">17</td></tr><tr><td class="CalWeekendDay" align="center">18</td><td align="center">19</td><td align="center">20</td><td align="center">21</td><td align="center">22</td><td align="center">23</td><td class="CalWeekendDay" align="center">24</td></tr><tr><td class="CalWeekendDay" align="center">25</td><td align="center">26</td><td align="center">27</td><td align="center">28</td><td align="center">29</td><td align="center">30</td><td class="CalOtherMonthDay" align="center">1</td></tr><tr><td class="CalOtherMonthDay" align="center">2</td><td class="CalOtherMonthDay" align="center">3</td><td class="CalOtherMonthDay" align="center">4</td><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td><td class="CalOtherMonthDay" align="center">7</td><td class="CalOtherMonthDay" align="center">8</td></tr>
		<div id="leftcontentcontainer">
			<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值