Effacer les filtres
Effacer les filtres

Integration of a function multiplied by an array

3 vues (au cours des 30 derniers jours)
Ron Nativ
Ron Nativ le 8 Déc 2021
Commenté : Ron Nativ le 8 Déc 2021
Hi all,
I want to integrate a symbolic function which is multiplied by a vector, for example:
syms x
y1 = linspace(0,1,10);
y2 = @(x) x.*y1;
q = integral(y2,0,1);
However, the integral execution fails due to 'Matrix dimensions must agree.'.
Is there a solution for this?
Thanks!
Ron

Réponse acceptée

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh le 8 Déc 2021
your y2 function return Array for every single number as it's input.
syms x
y1 = linspace(0,1,10);
y2 = @(x) x.*y1;
y2(1)
ans = 1×10
0 0.1111 0.2222 0.3333 0.4444 0.5556 0.6667 0.7778 0.8889 1.0000
according to documentation of integral function if fun has Array output, you should use option ArrayValued:
q = integral(y2,0,1,'ArrayValued',true)
q = 1×10
0 0.0556 0.1111 0.1667 0.2222 0.2778 0.3333 0.3889 0.4444 0.5000

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by