Borrar filtros
Borrar filtros

Matrix of functions of two variables

21 visualizaciones (últimos 30 días)
Arijit De
Arijit De el 9 de Mayo de 2013
I want to generate a matrix whose elements are functions of two variables, say F=f(t1).*f(t2), where t1 varies along row and t2 along column. How to construct such a matrix? Thanks.
  2 comentarios
James Kristoff
James Kristoff el 9 de Mayo de 2013
Could you please clarify what you are trying to do?
I am not sure if you are trying to make a matrix which contains functions that have two inputs e.g.
[ f1_1(x,y), f1_2(x,y), f1_3(x,y);...
f2_1(x,y), f2_2(x,y), f2_3(x,y);...
f3_1(x,y), f3_2(x,y), f3_3(x,y) ]
or if you have two functions, one for column vectors and one for row vectors, and you would like to multiply the output of these two functions to create a matrix,
or do you have some matrix,
T = [ t1_1, t1_2, t1_3;...
t2_1, t2_2, t2_3;...
t3_1, t3_2, t3_3 ]
and you would like to apply one function to the rows of T and another to the columns of T,
or is it something else?
Arijit De
Arijit De el 9 de Mayo de 2013
Editada: Arijit De el 9 de Mayo de 2013
Thanks for your comment! Let me clarify: Here I know a function f(t). Say, t1 = t2 = 1, 2, 3. So, I want to construct the matrix: F = [f(t1)f(t2)] = [f(1)f(1) f(2)f(1) f(3)f(1); f(1)f(2) f(2)f(2) f(3)f(2); f(1)f(3) f(2)f(3) f(3)f(3)]

Iniciar sesión para comentar.

Respuesta aceptada

James Kristoff
James Kristoff el 9 de Mayo de 2013
Editada: James Kristoff el 9 de Mayo de 2013
If the function f(t) is linear with respect to t (e.g. f(t) = t.*4 + log(5)) then you can simply multiply your inputs and pass the result to f:
t1 = 1:3;
t2 = 1:3;
T = t1'*t2; % this creates a matrix T
F = f(T); % or F = f(t1'*t2);
If the function f(t) is non-linear with respect to t (e.g. f(t) = t.^2) then you could do the following:
t1 = 1:3;
t2 = 1:3;
f1 = f(t1);
f2 = f(t2);
F = f1'*f2; % or F = f(t1)'*f(t2);
This should also work for if f(t) is linear.
Both of these methods require the function f(t) to be written to allow for element-wise mathematics (i.e. using .* in place of * and .^ in place of ^ etc.)

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 9 de Mayo de 2013
F = bsxfun(@times,t1,t2)
And for more info:
doc bsxfun
  2 comentarios
Arijit De
Arijit De el 9 de Mayo de 2013
Editada: Sean de Wolski el 9 de Mayo de 2013
Thanks for the answer; but I am not doing pairwise (binary) multiplication; let me clarify: Here I know a function f(t). Say, t1 = t2 = 1, 2, 3. So, I want to construct the matrix:
F = [f(t1)f(t2)] = [f(1)f(1) f(2)f(1) f(3)f(1); f(1)f(2) f(2)f(2) f(3)f(2); f(1)f(3) f(2)f(3) f(3)f(3)]
Sean de Wolski
Sean de Wolski el 9 de Mayo de 2013
if f is a scalar function then use
bsxfun(@f,t1,t2)
or construct f on the fly
bsxfun(@(x,y)f(x).*f(y),t1,t2)
It's really not quite clear what f is otherwise...

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by