Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error

3 Ansichten (letzte 30 Tage)
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)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Mai 2021
fprintf('The root is: %d\n' c)
^
^
You need a comma

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by