微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Matlab二分法

如何解决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 举报,一经查实,本站将立刻删除。