fplot - vectorisation with inequalities
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Star Strider
le 2 Juil 2019
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 commentaires
Voir également
Catégories
En savoir plus sur Measurements and Feature Extraction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!