matlab优化的参数传递

上传人:206****923 文档编号:41710368 上传时间:2018-05-30 格式:DOC 页数:3 大小:58.50KB
返回 下载 相关 举报
matlab优化的参数传递_第1页
第1页 / 共3页
matlab优化的参数传递_第2页
第2页 / 共3页
matlab优化的参数传递_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《matlab优化的参数传递》由会员分享,可在线阅读,更多相关《matlab优化的参数传递(3页珍藏版)》请在金锄头文库上搜索。

1、1. 初学者最爱用但是最不提倡的方法:全局变量法 适用于 MATLAB7 以及以前或者以后的版本 function withaddtionpara1 global b c b = 2; c = 3.5; x0 =0; options = optimset(Display, off); % Turn off Display y = fsolve(poly, x0, options) function y = poly(x) % Compute the polynomial. global b c y = x3 + b*x + c; 2. 直接传递法 适用于 MATLAB7 以及以前或者以后的版本

2、 根据: X=FSOLVE(FUN,X0,OPTIONS,P1,P2,.) passes the problem-dependent parameters P1,P2,. directly to the function FUN: FUN(X,P1,P2,.). Pass an empty matrix for OPTIONS to use the default values. 如果 options 不需要设置,则用空矩阵()占位 function withaddtionpara2 b = 2; c = 3.5; x0 =0; options = optimset(Display, off)

3、; % Turn off Display y = fsolve(poly, x0, options,b,c) function y = poly(x,b,c) % Compute the polynomial. y = x3 + b*x + c; 3. 采用 evalin 以及 assignin 函数法 适用于 MATLAB7 以及以前或者以后的版本 function withaddtionpara3 b = 2; c = 3.5; x0 =0; assignin(base,b,b); assignin(base,c,c); options = optimset(Display, off);

4、% Turn off Display y = fsolve(poly, x0, options) function y = poly(x) % Compute the polynomial. b = evalin(base,b); c = evalin(base,c); y = x3 + b*x + c; 4. 匿名函数法(Anonymous function) 适用于 MATLAB7 以及以后的版本 function withaddtionparas4 options = optimset(Display, off); % Turn off Display b =2; c = 3.5; x0

5、 =0; y = fsolve(x)mypoly(x,b,c), x0, options) function y = mypoly(x,b,c) y = x3 + b*x + c; 5. 嵌套函数法(nested function) 适用于 MATLAB7 以及以后的版本 function withaddtionpara5 b =2; c = 3.5; x0 =0; options = optimset(Display, off); % Turn off Display y = fsolve(poly, x0, options) function y = poly(x) % Compute t

6、he polynomial. y = x3 + b*x + c; end end 6. 采用文件传递(有些太笨拙了的办法) 适用于 MATLAB7 以及以前或者以后的版本 function withaddtionpara6 b = 2; c = 3.5; x0 =0; save paras b c options = optimset(Display, off); % Turn off Display y = fsolve(poly, x0, options) function y = poly(x) % Compute the polynomial. load paras.mat y = x3 + b*x + c;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号