Matrix as an output of a function

In summary, the person is trying to integrate a function over a real number range, but is having trouble picking up the matrix elements. They need to save the matrix as another variable and then do the integration.
  • #1
phynewb
13
0
Hi guys

I am new to matlab. I have a question in how to pick up matrix elements as a output of a function.

Code:
function result=test(E)
result=[1,2,3;4,5,6]*E;

For each E, test(E) will generate a 2x3 matrix.
I wonder how to pick up the matrix element,say test(2)(1,3).
When I type test(2)(1,3), it shows
? Error: ()-indexing must appear last in an index expression.
So how can I pick up the matrix element?
Thank you.
 
Physics news on Phys.org
  • #2
Code:
x = test(1);
x(1,3)
 
  • #3
Thank you a-tom-ic.
So I need other space to save the matrix first.
 
  • #4
But here comes the other question.
I need to integrate test(E)(1,3): int(test(E)(1,3),E1,E2).
If I set x=test(E), then int(x,E1,E2) will be problematic as shown "Undefined function or variable 'E'.
Is any way to solve this problem? Thank you for help.
 
  • #5
HI Phynewb,

i'm sorry i don't understand what your trying to do! Supply more information on your variables and the task. What is E? The int-Function is symbolic toolkit isn't it?
Code:
syms E;
int(E)
int(E,1,2)
 
  • #6
Thanks a-tom-ic.

Say, f1(E),f2(E),f3(E) are three functions. Here E is real number and the outputs are nxn real matrices.
Define F(E)=f1(E)*f2(E)*f3(E). So E is also an number and output is a matrix.
The purpose is to calculate the integration of F(E)(a,b) over E from E0 to E1. Here F(E)(a,b) means the (a,b) matrix element of F(E) and it is a number:
int(F(E)(a,b),E0,E1).

As you said, I cannot pick up the (a,b) element by F(E)(a,b). I have to save it as other variable, say G. Let G=F(E) and then take G(a,b).
But once you save it as other variable, how can I do the integration? Because G has no E-dependence.
int(G(a,b),E0,E1) is problematic!
I wonder if anyway to solve the problem.
Hopefully I explain it clearly.
 

FAQ: Matrix as an output of a function

1. What is a matrix in mathematics?

A matrix is a rectangular array of numbers or symbols that are arranged in rows and columns. It is used to represent mathematical and statistical data and operations.

2. How is a matrix used as an output of a function?

In mathematics, a function is a relationship between input values and output values. A matrix can be used as the output of a function to represent the result of a mathematical operation or transformation on the input values.

3. What are the elements of a matrix?

The elements of a matrix are the numbers or symbols that are contained within the rows and columns of the matrix. Each element is identified by its position in the matrix, with the row number first and the column number second.

4. Can a matrix have different dimensions as an output of a function?

Yes, a matrix can have different dimensions as an output of a function. The dimensions of a matrix depend on the number of rows and columns in the matrix, and these can vary depending on the mathematical operation or transformation performed by the function.

5. What are some applications of using a matrix as an output of a function?

Matrices are used in many areas of mathematics, science, and engineering. They can be used to solve systems of linear equations, represent data in statistics, and perform transformations in geometry. Matrices are also commonly used in computer graphics and computer programming for image processing and data manipulation.

Similar threads

Replies
2
Views
938
Replies
1
Views
1K
Replies
2
Views
3K
Replies
1
Views
1K
Replies
2
Views
1K
Replies
2
Views
1K
Replies
1
Views
2K
Replies
1
Views
1K
Back
Top