MATLAB: expressing a double index equation as a matrix

In summary, the conversation revolves around a new user inquiring about how to create a matrix in MATLAB using a for loop. The expert suggests using the documentation for guidance and provides a possible code solution for the user's specific equation. The user expresses gratitude and states that they have completed their task.
  • #1
Deathcrush
40
0
Just an urgent doubt, I am 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?
 
Physics news on Phys.org
  • #2
Can you give us an example? What you've said is on the vague side.
 
  • #3
like for example, if I have Iij=vi/vj considering that I know v for every i or j
 
  • #4
Deathcrush said:
Just an urgent doubt, I am 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
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 I am trying to get a 10x10 matrix :S
 
  • #6
Deathcrush said:
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
oh thanks a lot Grep, that REALLY helped me, now I've finished :)
 

What is MATLAB and how is it used in expressing double index equations as matrices?

MATLAB (Matrix Laboratory) is a programming language and numerical computing environment used for data analysis, visualization, and algorithm development. It allows for efficient manipulation and storage of matrices, making it useful for expressing double index equations in matrix form.

What is a double index equation?

A double index equation is an equation that contains two variables, typically represented by two indices or subscripts. These equations are often used in mathematics and scientific fields to represent relationships between two sets of data.

Why is it useful to express double index equations as matrices in MATLAB?

Expressing double index equations as matrices in MATLAB allows for easier manipulation and computation of large sets of data. It also allows for the use of built-in functions and operations specifically designed for matrices, making the coding process more efficient and accurate.

How do you express a double index equation as a matrix in MATLAB?

To express a double index equation as a matrix in MATLAB, you can use the built-in colon operator to create a range of values for each index. These values can then be used to create a matrix and perform calculations using matrix operations and functions.

What are some important considerations when expressing a double index equation as a matrix in MATLAB?

When expressing a double index equation as a matrix in MATLAB, it is important to ensure that the dimensions of the matrices match, as matrix operations can only be performed on matrices with the same dimensions. It is also important to consider the order of the indices, as this can affect the outcome of the equation. Additionally, it is important to properly initialize and store the matrix to avoid errors and ensure accurate results.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
934
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
797
  • Engineering and Comp Sci Homework Help
Replies
7
Views
958
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
799
Back
Top