马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
共包含五个 m文件
main.m
- function y=main(x)
- %This program uses the steepest_down + conjugate_grad method
- %to calculate the minimum of the function f(x)=x(1)^2+2*x(2)^2
- format long
- eps=input('please input your accuracy:');
- %eps is the demmanded accuracy on the norm of
- %the gradient of the objective function
- m=1;
- %m is the count of the iteration step of the algorithm
- iterstep(1,:)=x;
- %iterstep contains the intermediate points of iteration
- while m<=3
- while norm(gradobject1(x))>eps
- grad=gradobject1(x);
- alpha=goldsplictobj(x);
- x=x-alpha*grad;
- iterstep(m+1,:)=x;
- m=m+1;
- end
- end
- while norm(gradobject1(x))>eps
- x1=iterstep(m-1,:);
- x2=iterstep(m,:);
- grad1=gradobject1(x1);
- grad2=gradobject1(x2);
- beta=(norm(gradobject1(x2))/norm(gradobject1(x1)))^2;
- S=-grad2-beta*grad1;
- x2=x2-alpha*S;
- x=x2;
- iterstep(m+1,:)=x;
- m=m+1;
- end
- step=max(size(iterstep))-1
- x
- iterstep
- plot(iterstep(:,1),iterstep(:,2));
- %Draw the search trajectory
复制代码
[ 本帖最后由 suffer 于 2006-10-20 15:10 编辑 ] |