Why wont the divide operator work?

4 次查看(过去 30 天)
Julia Sircar
Julia Sircar 2016-11-28
回答: Mischa Kim 2016-11-28
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?

回答(1 个)

Mischa Kim
Mischa Kim 2016-11-28
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));

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by