|
楼主和我论坛生日一样哦,呵呵,你的函数用到符号运算了,f返回的是符号数值,需要转化下。关于MATLAB符号运算,最好用它来推导方程,得到符号函数表达式后用char转化成字符串然后用eval转化成匿名函数。如下:
- function test
- t=sym('exp(0.1*(x-0.925656)/(0.99999-x))+exp(0.3*(y-0.925656)/(0.99999-y))-z*(x*y-0.95)');
- dyf1 = eval( ['@(x,y,z) ', char( diff(t,'x') ),';']);
- dyf2 = eval( ['@(x,y,z) ', char( diff(t,'y') ),';']);
- dyf3 = eval( ['@(x,y,z) ', char( diff(t,'z') ),';']);
- function f = funsss(p)
- x=p(1);
- y=p(2);
- z=p(3);
- f=[dyf1(x,y,z);dyf2(x,y,z);dyf3(x,y,z)];
- end
- options.MaxIter=1e12;
- options.MaxFunEvals=1e8;
- fsolve(@funsss,[0.986;0.963;0.5],options)
- end
复制代码 运行结果:
- Optimization terminated: first-order optimality is less than options.TolFun.
- ans =
- 0.9818
- 0.9676
- 31.8249
复制代码
[ 本帖最后由 rocwoods 于 2010-7-16 16:10 编辑 ] |
评分
-
1
查看全部评分
-
|