Creating Matrices in Matlab

  • MATLAB
  • Thread starter glyvin
  • Start date
  • #1
4
0

Main Question or Discussion Point

Hi, I'm trying to write an SOR program in Matlab and have everything done, except I cannot figure out how to create a matrix of the following form without manually typing everything in:
x=(1,0,...,0,1)T for various sized matrices.

Thank you for your help.
 

Answers and Replies

  • #2
51
0
What is x equal to? Is it x=(1,0,1,0,....,1,0) or x=(1,0,0,1,1,0,0,1,.....,0,1)

In the first case, the expression "1,0" appears over and over again
In the second case, the expression "1,0,0,1" appears over and over again

Here is an idea for the first case:

n=10 <-- any number
x=zeros(n,1);
for i=1:n
if(mod(i,2)!=0)
x(i)=1;
endfor
 
  • #3
29
4
I think glyvin wants a set of zeros inside a a vector with only ones at each end.

This can be done fairly simply with something like
x=zeros(n,1);
x(1)=1; x(end)=1;
 

Related Threads on Creating Matrices in Matlab

Replies
1
Views
3K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
5
Views
4K
Replies
1
Views
4K
  • Last Post
Replies
4
Views
2K
Replies
3
Views
1K
Replies
28
Views
54K
Replies
1
Views
3K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
2
Views
2K
Top