Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters. ERROR in plotting graph
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jim Wilson Owusu
le 9 Mai 2021
Commenté : Jim Wilson Owusu
le 14 Mai 2021
clear all
close all
clc
tol=input ('Enter TOLERANCE number:') ;
n=input('Enter 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)
plot (f=@(x), f(XR_1), 'pre')
0 commentaires
Réponse acceptée
Cris LaPierre
le 10 Mai 2021
Your plot syntax is wrong. You cannot define a variable (f) inside your plot command. Use the documentation to identify a valid syntax.
The variable XR_1 is not defined in your code, either.
I see you have defined pre as a variable, but are passing it in as a character array to the plot command in what should be the linespec input.
Since you are only plotting a single point, you will want to include a marker style in your linespec. Perhaps try replacing your plot command with this.
plot(c, f(c),'ro')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots 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!