Matlab二分法

问题描述

我正在尝试编写一个程序来在 GNU 八度音阶上查找根目录

%this is program to calculate root of Non linear differential eqn

display('you can change function in bsfun.m')
a=input("enter maximum value\t");
b=input("entr minimum value\t");
e=input("enter tolerence\t");
if (bsfun(a)*bsfun(b)>0)
  display("you have not assumed right values")
endif
 
while ((b-a)>e)
  c=(b+a)/2;    %find middile point
  disp c
  if (bsfun(c)==0)    %check middile point is the root 
    break
  elseif (bsfun(a)*bsfun(c)<0)    % Decide the side to repeat the steps
    b=c;
  else 
    a=c;
  endif
end
fprintf("The root is %f\n",c);

哪里

%bisection Function
function out = bsfun(x) 
  out = (x.^2)+(2.1*x)-8.82;

但它不起作用 我是编程新手 也是在第一个程序上定义用户定义函数的任何方式(无需像在c中那样制作单独的文件

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)