What wrong in this code

2 vues (au cours des 30 derniers jours)
Niati Rachid
Niati Rachid le 17 Oct 2020
Commenté : Steven Lord le 18 Oct 2020
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 commentaires
Adam Danz
Adam Danz le 17 Oct 2020
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 le 18 Oct 2020
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Desktop dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by