fplot - vectorisation with inequalities
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am using fplot for the first time, and I am getting the message: Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
After some researches, I found out that fplot requires that I vectorise my code. So I switched / by ./ . However I have some if, elseif, else with inequalities as conditions.
function [phio] = phi_i(x,xi,i)
N=size(x,1)-1;
if i==1
if (xi(1)<=x && x<=xi(2))
phio=(xi(2)-x)./(xi(2)-xi(1));
else
phio=0;
end
elseif i==N+1
if (xi(N)<=x && x<=xi(N+1))
phio=(x-xi(N))./(xi(N+1)-xi(N));
else
phio=0;
end
else
if (xi(i-1)<=x && x<xi(i))
phio=(x-xi(i-1))./(xi(i)-xi(i-1));
elseif (xi(i)<=x && x<=xi(i+1))
phio=(xi(i+1)-x)./(xi(i+1)-xi(i));
else
phio=0;
end
end
end
I am using it such that
xi=0:0.5:10;
phii=@(x)phi_i(x,xi,6);
fplot(@(x)phii(x),[0 10],'b')
I guess that all the inequalities such as xi(i-1)<=x are a problem, if xi(i-1) is a scalar and x a vector, isn't it?
How could I remedy that? Thanks
Alex
댓글 수: 0
답변 (1개)
Star Strider
2019년 7월 2일
The fplot function may be a bit sensitive with respect ot the functions you give it. Your code runs without error (only the warnings), so just ignore them.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Measurements and Feature Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!