MATLAB: expressing a double index equation as a matrix

  • Thread starter Deathcrush
  • Start date
  • #1
Deathcrush
40
0
Just an urgent doubt, im new to matlab.

So imagine an equation that has two indexes, and that can be expressed as a matrix, how can I do something like this in Matlab? using a for cycle?
 

Answers and Replies

  • #2
36,311
8,281
Can you give us an example? What you've said is on the vague side.
 
  • #3
Deathcrush
40
0
like for example, if I have Iij=vi/vj considering that I know v for every i or j
 
  • #4
Grep
298
2
Just an urgent doubt, im new to matlab.

So imagine an equation that has two indexes, and that can be expressed as a matrix, how can I do something like this in Matlab? using a for cycle?

Often unnecessary to use a for loop, but you can always do things like this:
Code:
a = [1 2 3; 4 5 6; 7 8 9];
for i = 1:3,
    for j = 1:3,
        a(i,j)
    end
end
Matrices is pretty much what MATLAB is all about. Probably, all your beginner questions can be found in various MATLAB documentation. I'd suggest finding it and reading it.
 
  • #5
Deathcrush
40
0
well, the problem is that my equation is not so simple, it is actually a pretty big fluid dynamics model for calculating the viscosity of a mixture of 10 gases, so I have an equation, lots of constant properties, and Im trying to get a 10x10 matrix :S
 
  • #6
Grep
298
2
like for example, if I have Iij=vi/vj considering that I know v for every i or j
I'm rusty on my MATLAB, but something like this perhaps?

Code:
for i = 1:length(v),
    for j = 1:length(v),
        r(i,j) = v(i)/v(j);
    end
end
r
Note that division by zero will happen if there's a single 0 in there...
 
  • #7
Deathcrush
40
0
oh thanks a lot Grep, that REALLY helped me, now I've finished :)
 

Suggested for: MATLAB: expressing a double index equation as a matrix

  • Last Post
Replies
7
Views
70
Replies
1
Views
395
Replies
10
Views
321
  • Last Post
Replies
1
Views
369
  • Last Post
Replies
3
Views
369
  • Last Post
Replies
1
Views
35
  • Last Post
Replies
3
Views
60
Replies
3
Views
1K
Replies
6
Views
739
  • Last Post
Replies
6
Views
770
Top