Generate anonymous functions from vectors

2 visualizaciones (últimos 30 días)
Yang Metin
Yang Metin el 29 de Ag. de 2020
Comentada: Walter Roberson el 30 de Ag. de 2020
For example, the vector [a b c ....], I want to generate an anonymous function fun=@(t) -(a*t(1)+b*t(2)+c*t(3)+.....) ,How to do it?

Respuesta aceptada

Matt J
Matt J el 29 de Ag. de 2020
Editada: Matt J el 29 de Ag. de 2020
fun=@(t) -( vector(:).' * t(:) )
  3 comentarios
Yang Metin
Yang Metin el 30 de Ag. de 2020
What does " .' " do?
Walter Roberson
Walter Roberson el 30 de Ag. de 2020
.' is transpose -- non-conjugate transpose.
vector(:) re-arranges the vector as a column vector no matter whether it was a row vector or column vector to start with. Transpose of that makes the column vector into a row vector. So vector(:).' is one way of forcing vector to be a row vector. Another way of writing it would be
reshape(vector,1,[])

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by