Problem using the erfi function from Mupad in Matlab command Window

12 vues (au cours des 30 derniers jours)
Mohamed Yassin OUKILA
Mohamed Yassin OUKILA le 8 Juil 2011
Hello every one, I want to use the erfi function, and since it doesn't exist in Matlab I tried to call it from Mupad. It works fine for numbers like 1, 1.3, .. however, it doesn't work for an array this is my function :
function ans=erfi(t)
f = feval(symengine,'erfi',t);
format long;
ans = double(f);
and when I put in the command window:
>> erfi(1)
erfi (1.3)
erfi(2)
ans =
1.650425758797543
ans =
2.956086576851622
ans =
18.564802414575553
it works. But when I put ( and that's what I need) :
>> erfi([1;2;3])
??? Error using ==> mupadengine.mupadengine>mupadengine.feval at 144
MuPAD error: Error: argument must be of 'Type::Arithmetical' [erfi]
Error in ==> erfi at 2
f = feval(symengine,'erfi',t);
I have this as an error... I hope I explained my problem for you guys..I'm waiting for you help Thanks :)

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 8 Juil 2011
correct
function out=erfi(t)
out = arrayfun(@(i1)double(feval(symengine,'erfi',t(i1))),1:length(t));
end
EDIT
function out=erfi(t)
out = zeros(1,numel(t));
for i1 = 1:numel(t)
out(i1) = double(feval(symengine,'erfi',t(i1)));
end
end
  2 commentaires
Mohamed Yassin OUKILA
Mohamed Yassin OUKILA le 8 Juil 2011
Thanks dude...that really helped...but can you explain what have you done to make it work please? :)
Andrei Bobrov
Andrei Bobrov le 8 Juil 2011
We use function 'arrayfun' , read help about 'arrayfun', more can use loops 'for...end'. see answer EDIT.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by