What wrong in this code

2 次查看(过去 30 天)
Niati Rachid
Niati Rachid 2020-10-17
评论: Steven Lord 2020-10-18
clear clc while ('t') disp('Input endpoints that contain the root function x*') deff('F=f(x)','F=cos(x)+x') a=input("First end") b=input("Second end ") if f(a)*f(b)>0 then disp ("please check the endpints a or b that verify f(a)* f(b)<0") end while f(a)*f(b)<0 %chek the existence of roots in the interval [a,b] n=1 start counter while abs(b-a)>0 %eps stopping criteria m=(a+b)/2 n=n+1 if f(m)*f(a)<0 then a=m else b=m end end disp("m= "+string(m)) %display x root-result disp("f("+string(m)+"="+string(f(m))) %display F(m) results disp("n="+string(n)) %display iterations number end cont=input("do you want to continuel? Y or N !?","string") if cont=="N" then break end end
  2 个评论
Adam Danz
Adam Danz 2020-10-17
Edit your question so that your code is formatted properly and appears within a code block by using the Code Toggle tool [more info].
Steven Lord
Steven Lord 2020-10-18
In addition to reformatting your code to make it easier for us to read and understand, please explain why you believe something is wrong in this code.
  • Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support using the telephone icon in the upper-right corner of this page so we can investigate.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Desktop 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by