Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jim Wilson Owusu
el 9 de Mayo de 2021
Comentada: Jim Wilson Owusu
el 9 de Mayo de 2021
clear all
close all
clc
tol=input ('Determine tolerance number:') ;
n=input('Determine iteration number:');
n=100;
f=@(x) (x+1-2*sin(pi*x));
a=0;
b=0.5;
if f(a) * f(b)>0
warning('ít is not applicable:')
elseif f(a)==0
fprintf('The root is %d', a)
elseif f(b)==0
fprintf('The root is %d', b)
end
pre=0;
for i=1:n
c=(a+b)/2;
if f(c)==0
fprintf('The root is: %d\n' c)
elseif f(c)*f(b)<0
a=c;
elseif f(c)*f(a)<0
b=c;
end
if abs(c-pre)<=tol
break;
end
pre=c;
end
fprintf('The root is %g with the %.3d tolerance',c,tol)
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!