Using integral function for a function which is defined with an integral
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to use the integral function in Matlab 2012a to integrate the function
phi = @(x) integral(@(t) exp(-t.^2./2),-inf,x);
but I get an error when the integrate function passes vector-valued x to
integral(@(t) exp(-t.^2./2),-inf,x);
I tried to define a function
function out = innerIntegralMultiple(x)
inner = @(t) exp(-t.^2./2);
if(isscalar(x))
out = integral(inner,-inf,x);
return;
end
out = zeros(length(x),1);
for i=1:length(x)
out = integral(inner,-inf,x(i));
end
end
and define phi as
phi = @(x) innerIntegralMultiple(x)
but I get errors about the number of arguments the function returns when I try this definition.
Is there a way to do what I want?
0 commentaires
Réponses (1)
Mike Hosea
le 5 Juin 2012
>> phi = @(r)arrayfun(@(x)integral(@(t)exp(-t.^2./2),-inf,x),r);
>> phi(-3:3)
ans =
Columns 1 through 5
0.003383692573953 0.057026123992892 0.397689745423351 1.253314137315500 2.108938529207654
Columns 6 through 7
2.449602150637674 2.503244582076109
0 commentaires
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!