deval and fplot give strange warnings
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have found the following strange behaviour:
1) First, I solve an initial value problem for an ode numericall (say, with ode45)
2) Next, I use deval to define a function handle with the solution
3) Finally, I use fplot to plot the function handle.
And here comes the strange thing: for scalar equations, I get a warning from fplot. I have checked this with R2019a and R2018a. I do not have any other release now to test, but I am quite sure I did not get the warning with R2016b.
And what is more strange: for systems of odes, the warning does not appear.
Sample code follows,
Thanks,
Mariano
%% Scalar test
sol = ode45(@(t,y) t*y,[0,1],1);
y = @(t) deval(sol,t);
figure(1),clf(1)
subplot(2,1,1)
fplot(y,[0,1])
% Warning appears:
% 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.
%
% But the function seems to work properly with array inputs
y([0.27,1/pi])
%% System test
% And more surprinsingly, for systems it works without warnings
sol2 = ode45(@(t,y) [y(2);-y(1)],[0,10],[1;-2]);
y1 = @(t) deval(sol2,t,1);
y2 = @(t) deval(sol2,t,2);
subplot(2,1,2)
fplot(y1,[0,10])
hold on
fplot(y2,[0,10])
% No warning at all !!!
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations 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!