Effacer les filtres
Effacer les filtres

i want to put n and counter in one matrix

1 vue (au cours des 30 derniers jours)
yonatan friedman
yonatan friedman le 12 Déc 2020
for n=4:50
a=[];
e = ones(n,1);
A1 = spdiags([-e 0*e -e 4*e -e 0*e -e],-3:3,n,n);
full(A1);
A=full(A1);
b=zeros(n,1);
b(1)=1; b(end)=1;
x=zeros(n,1);
L=tril(A,-1);
U=triu(A,1);
D=diag(A);
B=-1./D.*(L+U);
c=(1./D).*b;
flag=0;
counter=0;
epsilon=10^(-3);
while flag==0
counter=counter+1;
if counter>100000
error('too much')
end
x_new=B*x+c;
if max(abs((x_new-x)./x_new))<epsilon
flag=1;
end
x=x_new;
end
fprintf('%g %g\n',counter,n)
end

Réponses (1)

Abhishek Gupta
Abhishek Gupta le 15 Déc 2020
Hi,
As per my understanding, you want to create a matrix containing 'n' and 'counter' variables. One can do this task by appending a row, containing 'n' and 'counter' variables, at the end of the matrix on every iteration of the loop.
out = []; % output matrix
for n = 4:50
% Your Code Here %
out = [out; [n, counter]]; % append row containing n and counter
end
Also, referring you to the following link for more information: -

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by