fsolve error: no function or method found

强颜欢笑 提交于 2019-12-12 05:40:09

问题


I wrote this code in octave:

syms z;
f=z-2;
fsolve("f",0.)

Then this gives the error

@f: no function and no method found.

Also using fsolve(@f,0) gives the same error

When I write code as:

syms z;
f=z-2;
fsolve(f,0.)

Then this gives the error

ind2sub: subscript indices must be either positive integers less than 2^31 or logicals.

Please explain to me how to actually use fsolve.


回答1:


% syms z;      % Not needed, actually slows down the code
f=@(z)(z-2); 
fsolve(f,0.)

You're missing the @ symbol, which is a function handle. This tells Octave that f is not a variable, but actually is a(n anonymous) function, in this case of z, which is the first argument.

You'll probably want to have z to be a regular variable, because making it symbolic turns MATLAB from a speeding race car to a drudging farm vehicle. Unless there's a specific reason to have z symbolic (I cant think of any in case of usage with fsolve)' it's best to avoid symbolic maths.



来源:https://stackoverflow.com/questions/37890794/fsolve-error-no-function-or-method-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!