How can i change the 1st row 1st column and last row last column values in a tridiagonal matrix
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Harin Nelumdeniya
el 22 de Abr. de 2018
Comentada: Vaishali
el 31 de Jul. de 2024
n=5;
A=zeros(n,n);
for i=1:n
if (i>1)
A(i-1,i)=-100;
end
A(i,i)=300;
if (i<n)
A(i+1,i)=-100;
end
end
I wrote the code above to create a tridiagonal matrix. I need to separate the 1st row 1st column variable and the last row last column variable, so that i can assign a different value for these two variable's but im not sure how to write a statement to do this task.
2 comentarios
Dhamotharan
el 29 de Jul. de 2024
Change the element in the first row and last column of data to 0.5.
Respuesta aceptada
Are Mjaavatten
el 22 de Abr. de 2018
A(1,1) = 17;A(end,end) = 23;
You can create your original matrix without using a loop:
n = 5; A = diag(ones(1,n))*300-diag(ones(1,n-1)*100,-1)-diag(ones(1,n-1)*100,1);
0 comentarios
Más respuestas (1)
Dhamotharan
el 29 de Jul. de 2024
Change the element in the first row and last column of data to 0.5.
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!