Borrar filtros
Borrar filtros

Adding anonymous functions stored in a cell

1 visualización (últimos 30 días)
Aviral Srivastava
Aviral Srivastava el 2 de En. de 2024
Comentada: Dyuman Joshi el 2 de En. de 2024
I have a cell of functions, which I want to add after integration of each in the cell. Further, I have to multply each fucntion with a constant from another cell. This new cells of anonymous functions thus obtained is to be added .i.e the elements have to be summed up. I tried using a for loop. Following is a approach I used,but I do not seem to be getting the right constant i.e. in the function MATLAB just shows cons{j} instead of the actual value stored there (a symbolic constant). Neither am I getting the summed up total funtion. Kindly help.
f = {@(x)x , @(x)x^2}
syms a b
c = {a b}
g = @(y) y
h = 0;
for j=1:length(2)
h = @(x) c{j}*integral(f{j}(x), 0,1) + h
end

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 2 de En. de 2024
Use symbolic integration -
syms x a b
f = {x x^2}
f = 1×2 cell array
{[x]} {[x^2]}
c = [a b];
h = 0;
for j=1:numel(f)
h = c(j)*int(f{j}, x, 0, 1) + h;
end
h
h = 
  6 comentarios
Aviral Srivastava
Aviral Srivastava el 2 de En. de 2024
Thank you!
Dyuman Joshi
Dyuman Joshi el 2 de En. de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by