Borrar filtros
Borrar filtros

Writing summation inside function handle

1 visualización (últimos 30 días)
Saurabh Madankar
Saurabh Madankar el 10 de Nov. de 2021
Respondida: Aneela el 19 de Feb. de 2024
Hey,
I have this term
u = @(x) c(1)*f(3*(x-t(1)))+c(2)*f(3*(x-t(2)))+c(3)*f(3*(x-t(3)))+c(4)*f(3*(x-t(4)))+...
c(5)*f(3*(x-t(5)))+c(6)*f(3*(x-t(6)));
inside a function I have written. What I want is to write these six terms here using summation. So how should I go about it?
  3 comentarios
Saurabh Madankar
Saurabh Madankar el 10 de Nov. de 2021
Here f is also a function handle, a function of x (which I have defined as a linearly spaced vector) which returns a scalar value.
Saurabh Madankar
Saurabh Madankar el 10 de Nov. de 2021
And yes I can't pass a vector of elements to f. It takes only one element at a time.

Iniciar sesión para comentar.

Respuestas (1)

Aneela
Aneela el 19 de Feb. de 2024
Hi Saurabh Madankar,
You can make use of the “sum” and “arrayfun” MATLAB functions to write these 6 terms using summation.
u = @(x) sum(arrayfun(@(k) c(k) * f (3 * (x - t(k))), 1:6));
Refer to the following links for further details on “sum” and “arrayfun“ functions in MATLAB.

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