Problem using the erfi function from Mupad in Matlab command Window
13 次查看(过去 30 天)
显示 更早的评论
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 :)
0 个评论
回答(1 个)
Andrei Bobrov
2011-7-8
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 个评论
Andrei Bobrov
2011-7-8
We use function 'arrayfun' , read help about 'arrayfun', more can use loops 'for...end'. see answer EDIT.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!