解决错误:找不到函数或方法 [英] fsolve error: no function or method found

查看:167
本文介绍了解决错误:找不到函数或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用八度写了这段代码:

I wrote this code in octave:

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

然后这给出了错误

@f:没有函数,没有找到方法.

@f: no function and no method found.

还使用fsolve(@f,0)会给出相同的错误

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

当我将代码编写为:

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

然后出现错误

ind2sub:下标索引必须是小于2 ^ 31的正整数或逻辑值.

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

请向我解释如何实际使用fsolve.

Please explain to me how to actually use fsolve.

推荐答案

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

您遗漏了@符号,它是一个函数句柄.这告诉Octave,f不是变量,但实际上是一个(n个匿名)函数,在本例中为z,这是第一个参数.

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.

您可能希望将z用作常规变量,因为将其符号化可将MATLAB从高速赛车变为缓慢的农用车.除非有特殊原因要使用z符号(除非与fsolve结合使用,否则我想都没有)',否则最好避免使用符号数学.

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.

这篇关于解决错误:找不到函数或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆