Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Octave 增量搜索方法脚本错误_Octave_Symbolic Math_Incremental Search - Fatal编程技术网

Octave 增量搜索方法脚本错误

Octave 增量搜索方法脚本错误,octave,symbolic-math,incremental-search,Octave,Symbolic Math,Incremental Search,我写了我的第一个八度脚本,这是一个用于根查找的增量搜索方法的代码,但是我遇到了许多我发现难以理解的错误。 以下是脚本: clear syms x; fct=input('enter your function in standard form: '); f=str2func(fct); % This built in octave function creates functions from strings Xmax=input('X maximum= '); Xinit=input(

我写了我的第一个八度脚本,这是一个用于根查找的增量搜索方法的代码,但是我遇到了许多我发现难以理解的错误。 以下是脚本:

clear 

syms x;

fct=input('enter your function in standard form: ');
f=str2func(fct); % This built in octave function creates functions from strings
Xmax=input('X maximum= ');

Xinit=input('X initial= ');

dx=input('dx= ');
epsi=input('epsi= ');
N=10; % the amount by which dx is decreased in case a root was found.

while (x<=Xmax)
    
    f1=f(Xinit);
    x=x+dx
    f2=f(x);
    if (abs(f2)>(1/epsi))
        disp('The function approches infinity at ', num2str(x));
        x=x+epsi;
    else
        if ((f2*f1)>0)
          x=x+dx;
    elseif ((f2*f1)==0)
        disp('a root at ', num2str );
        x=x+epsi;
    else
        if (dx < epsi)
          disp('a root at ', num2str);
          x=x+epsi;
        else
            x=x-dx;
            dx=dx/N;
            x=x+dx;
        end
    end
end
end  
以下是增量搜索方法的流程图:

问题发生在这一行:

fct=input('enter your function in standard form: ');
此处
input
获取用户输入并对其进行评估。它试图将其转换为一个数字。在下一行中

f=str2func(fct)
您假定
fct
是一个字符串

要解决问题,请告诉
input
以字符串形式返回用户的输入(请参阅):


问题发生在这一行:

fct=input('enter your function in standard form: ');
此处
input
获取用户输入并对其进行评估。它试图将其转换为一个数字。在下一行中

f=str2func(fct)
您假定
fct
是一个字符串

要解决问题,请告诉
input
以字符串形式返回用户的输入(请参阅):