Why wont the divide operator work?

13 vues (au cours des 30 derniers jours)
Julia Sircar
Julia Sircar le 28 Nov 2016
A = [1 2 1; 2 1 2; 1 2 1];
b = [1; 1; 1];
x = [6; 6; 6];
r = b-a*x;
p = r;
w = zeros(3);
tolerance = 10^(-6);
k = 0;
while norm(r) > tolerance
plot(k,log(norm(r))^2)/(dot(p,A*p));
x = x*p;
r1 = r - a*A*p;
b = (norm(r))^2/((norm(r))^2);
r=r1;
p=r1+b*p;
end
The script is returning an error on the divide operator in the code "plot(k,log(norm(r))^2)/(dot(p,A*p))..." why?

Réponses (1)

Mischa Kim
Mischa Kim le 28 Nov 2016
Julia, are you showing all the code? Looks like the variable a is not defined.
As for the plot command: one of the round brackets is misplaced. The way it is typed right now, MATLAB thinks that the command ends after the 2.
plot(k,log(norm(r))^2) /(dot(p,A*p));

Catégories

En savoir plus sur Mathematics 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