为了账号安全,请及时绑定邮箱和手机立即绑定

用FUNCTION搞定,怎么定义多元的如:y=x1*x2/x3?

用FUNCTION搞定,怎么定义多元的如:y=x1*x2/x3?

人到中年有点甜 2023-04-23 22:18:13
MATLAB运用优化工具解决问题时,怎么定义多元函数。一元的:function=文件名(x);y=2*x^2;..其中有要确定目标函数的么,用FUNCTION搞定,怎么定义多元的如:y=x1*x2/x3菜鸟求助,问题白痴,多多包涵
查看完整描述

1 回答

?
潇潇雨雨

TA贡献1833条经验 获得超4个赞

如果是多元函数的话,可以参考fminseach
Example 1

The Rosenbrock banana function is a classic test example for multidimensional minimization:
f=x(1)^2+a*x(2)^2; 目标函数 
The minimum is at (1,1) and has the value 0. The traditional starting point is (-1.2,1). The anonymous function shown here defines the function and returns a function handle called banana:
function f=myfun(x,a) 新建着这样的M文件
banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2;

Pass the function handle to fminsearch:

[x,fval] = fminsearch(banana,[-1.2, 1])  
用这样的格式条用fminseach以及M函数, 其中[-1.2,1]为优化其实点

This produces 运行以后的结果

x =

1.0000 1.0000

fval = 这个是优化点的函数值

8.1777e-010

This indicates that the minimizer was found to at least four decimal places with a value near zero.

查看完整回答
反对 回复 2023-04-25
  • 1 回答
  • 0 关注
  • 106 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信