Problem using the erfi function from Mupad in Matlab command Window
이전 댓글 표시
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 :)
답변 (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
Mohamed Yassin OUKILA
2011년 7월 8일
Andrei Bobrov
2011년 7월 8일
We use function 'arrayfun' , read help about 'arrayfun', more can use loops 'for...end'. see answer EDIT.
카테고리
도움말 센터 및 File Exchange에서 Error and Exponential Integral Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!