Define Matrix array as a function

21 views (last 30 days)
Hi everybody.
Would you please guide me how to define an array of a Matrix as a function? For example how can array or components of a Matrix be a Sinc function?
Thanks in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Oct 2017
In basic MATLAB, the closest you can get is to have a cell array of function handles that you would have to access and apply to the inputs. (Or, I suppose, an array of some kind of object oriented objects that you created yourself for this purpose.)
In the Symbolic Toolbox, each element of a symbolic array can be used to store a symbol that is a symbolic function. For example,
syms y(t)
A(t) = [sin(t), sinc(t), y]
A(pi/4)
ans =
[ 2^(1/2)/2, (4*sin(pi^2/4))/pi^2, y(pi/4)]
However, this formation is more
A = symfun([sin(t), sinc(t), y], t)
so you will see that A(t) = [ sin(t), sin(pi*t)/(t*pi), y(t)] where sinc(t) has been evaluated already instead of remaining as an unresolved function call.
If you were to instead use
A = [sin(t), sinc(t), y]
then although you would still see A = [ sin(t), sin(pi*t)/(t*pi), y(t)] looking exactly the same content, the result would not be a symbolic function, and attempting A(pi/2) for example would get you a subscript error.
It is not possible to construct a numeric array in which some of the entries are "macros" like in Excel such that changing other entries in the array would change the calculated result at that location.
  4 Comments
Marzieh Parsa
Marzieh Parsa on 21 Oct 2017
Edited: Walter Roberson on 21 Oct 2017
Respected Walter,
Thank you very much for your guidance.
Kind Walter, as I replied to Cam and Steven, I tried through your example to make the Matrix and I've attached the result. However, I think I'm not still in the point to make mentioned Matrix, means a 5 by 5 Matrix whose all components are a simple Sinc function, because I think now we have 5 vectors instead of a united Matrix:
A(t) =
[ sin(7*pi*t)/(7*t*pi), sin(5*pi*t)/(5*t*pi), sin(5*pi*t)/(5*t*pi), sin(3*pi*t)/(3*t*pi), 1]
[ sin(10*pi*t)/(10*t*pi), sin(3*pi*t)/(3*t*pi), sin(7*pi*t)/(7*t*pi), sin(6*pi*t)/(6*t*pi), sin(pi*t)/(t*pi)]
[ sin(10*pi*t)/(10*t*pi), sin(pi*t)/(t*pi), sin(4*pi*t)/(4*t*pi), sin(9*pi*t)/(9*t*pi), sin(pi*t)/(t*pi)]
[ sin(7*pi*t)/(7*t*pi), sin(pi*t)/(t*pi), sin(7*pi*t)/(7*t*pi), sin(9*pi*t)/(9*t*pi), sin(4*pi*t)/(4*t*pi)]
[ sin(3*pi*t)/(3*t*pi), sin(4*pi*t)/(4*t*pi), sin(3*pi*t)/(3*t*pi), sin(6*pi*t)/(6*t*pi), 1]
Actually, I want all the components remain a simple Sinc, which obviously will be Sin(pit)/(pit).
In another word, if we consider hij as a component of our Matrix, hij is a Sinc beam in which i is our Receiver and j will be the Transmitter, and we want to see the behavior of Sinc waveform in our interference limited environment.
So, I will be grateful for your further guidance to reach to such a Matrix.
Thanks a lot in advance.
Marzieh
Walter Roberson
Walter Roberson on 21 Oct 2017
You are getting confused by the display of the matrix. MATLAB puts decorations on it. Look at pretty(A) for example.
If all of the entries are to be the same then you could
A(t) = repmat(sinc(t), 5, 5);
However if all of the entries are the same then I do not think this would help you in your Receiver / Transmitter problem.

Sign in to comment.

More Answers (1)

Cam Salzberger
Cam Salzberger on 19 Oct 2017
Edited: Cam Salzberger on 19 Oct 2017
Hello Marzieh,
It seems like there may be a relatively fundamental misunderstanding here. Let me see if I can put it clearly.
Numeric arrays: These are simply numbers. These numbers may have meaning that you assign to them, but they don't represent anything by themselves. For example, if you do this:
x = 0:pi/20:2*pi;
ySin = sin(x);
ySinc = sinc(x); % If you have Signal Processing Toolbox
you have now created two numeric arrays. "ySin" doesn't represent that sine function, but it does contain the values gotten by calculating the sine function at each of the points in "x". Similarly for "ySinc".
Symbolic variables and functions: If you are using the Symbolic Math Toolbox, you can create symbolic variables and functions. For example:
syms x
f = sin(x);
Now "f" represents the sine function in a more fundamental way. However, it does not contain any numeric values yet, it is more of an instruction on how to perform the computation. You would compute it with:
subs(f, 0)
to substitute in the value of 0 for "x". You can have arrays of symbolic functions, which will produce array output:
f = [sin(x) cos(x)];
subs(f, pi)
Function handles: Similar to symbolic functions, these are more of instructions on how to perform the computation. However, while the symbolic functions can be used in further symbolic computation, solving, or simplifying, function handles are just instructions on how to run a particular function. That said, you can do something like this:
f = @sin;
Now you have a handle to the numeric sine function in MATLAB. You can compute values like this:
x = 0:pi/20:2*pi;
f(x)
You can have cell arrays of function handles, though it can be confusing trying to evaluate them all at once. Here's a quick example:
f = {@sin @cos};
cellfun(@(h) feval(h, 1), f)
I hope this helps to give you an overview of different "function types" in MATLAB.
-Cam
  4 Comments
Steven Lord
Steven Lord on 20 Oct 2017
So let's say that you were able to create a matrix A with "all elements are Sinc Function". How would you then try to use that matrix? Don't try to explain it with code or pseudocode; explain it in words as though we were completely unfamiliar with your application (because we are!)
Marzieh Parsa
Marzieh Parsa on 21 Oct 2017
Edited: Marzieh Parsa on 21 Oct 2017
Dear all,
Thanks to you dear Cam,Walter and Steven for your kind reply, sorry my Internet access is limited that's why I reply late.
By the way, I tried through Walter example to make the Matrix and I've attached the result. However, I think I'm not still in the point to make mentioned Matrix, means a 5 by 5 Matrix whose all components are a simple Sinc function, because I think now we have 5 vectors instead of a united Matrix:
A(t) =
[ sin(7*pi*t)/(7*t*pi), sin(5*pi*t)/(5*t*pi), sin(5*pi*t)/(5*t*pi), sin(3*pi*t)/(3*t*pi), 1]
[ sin(10*pi*t)/(10*t*pi), sin(3*pi*t)/(3*t*pi), sin(7*pi*t)/(7*t*pi), sin(6*pi*t)/(6*t*pi), sin(pi*t)/(t*pi)]
[ sin(10*pi*t)/(10*t*pi), sin(pi*t)/(t*pi), sin(4*pi*t)/(4*t*pi), sin(9*pi*t)/(9*t*pi), sin(pi*t)/(t*pi)]
[ sin(7*pi*t)/(7*t*pi), sin(pi*t)/(t*pi), sin(7*pi*t)/(7*t*pi), sin(9*pi*t)/(9*t*pi), sin(4*pi*t)/(4*t*pi)]
[ sin(3*pi*t)/(3*t*pi), sin(4*pi*t)/(4*t*pi), sin(3*pi*t)/(3*t*pi), sin(6*pi*t)/(6*t*pi), 1]
Actually, I want all the components remain a simple Sinc, which obviously will be Sin(pit)/(pit).
In another word, if we consider hij as a component of our Matrix, hij is a Sinc beam in which i is our Receiver and j will be the Transmitter, and we want to see the behavior of Sinc waveform in our interference limited environment.
So, I will be grateful for your further guidance to reach to such a Matrix.
Thanks a lot in advance.
Marzieh

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!