Matrix as an output of a function

Click For Summary

Discussion Overview

The discussion revolves around the use of MATLAB functions to generate matrices and how to access specific elements of these matrices as outputs. Participants explore issues related to indexing, variable storage, and integration of matrix elements over a specified range.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant asks how to access a specific element of a matrix generated by a function in MATLAB, noting an error when attempting to index directly.
  • Another participant suggests first storing the output of the function in a variable before accessing its elements.
  • A further question arises about integrating a specific matrix element over a range, leading to confusion about variable dependencies and the use of symbolic functions in MATLAB.
  • Clarification is sought regarding the nature of the variable E and the integration process, with a participant explaining their intention to integrate a specific matrix element derived from a product of functions.
  • Concerns are raised about how to handle variable dependencies when saving the matrix output to another variable for integration purposes.

Areas of Agreement / Disagreement

Participants express varying levels of understanding regarding the integration of matrix elements and the handling of variable dependencies. The discussion remains unresolved, with multiple competing views on how to approach the problem.

Contextual Notes

There are limitations related to the understanding of variable definitions and the symbolic toolkit in MATLAB, as well as the handling of matrix outputs and their elements for integration.

Who May Find This Useful

Individuals interested in MATLAB programming, particularly those working with matrix operations and symbolic mathematics.

phynewb
Messages
13
Reaction score
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
Code:
x = test(1);
x(1,3)
 
Thank you a-tom-ic.
So I need other space to save the matrix first.
 
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.
 
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)
 
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K