Why wont the divide operator work?

4 visualizzazioni (ultimi 30 giorni)
Julia Sircar
Julia Sircar il 28 Nov 2016
Risposto: Mischa Kim il 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?

Risposte (1)

Mischa Kim
Mischa Kim il 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));

Community Treasure Hunt

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

Start Hunting!

Translated by