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