How can I plot the vector field of a differential equation on the real line?

95 views (last 30 days)
Hello,
I´m trying to plot
for the differential equation x'=4x^2-16
  5 Comments

Sign in to comment.

Answers (1)

darova
darova on 7 Mar 2020
I reached some success. Look, it should me heplpfull
clc,clear
[X,Y] = meshgrid(-2:0.2:2);
F = @(X,Y) 4*Y.^2 - 16;
[x,y] = ode45(F,[-2 2],2-1e-4);
DY = F(1,Y);
DX = DY*0+1;
cla
h1 = quiver(X,Y,DX,DY);
h2 = streamline(X,Y,DX,DY,-2:2,1.9*ones(1,5));
set(h2,'color','g')
hold on
h3 = plot(x,y,'r');
hold off
legend([h1 h2(1) h3],'quiver','streamline','ode45 solution')
  4 Comments
darova
darova on 7 Mar 2020
Try this
[x,y] = ode45(F,[-2 2],2-1e-4);
x1 = linspace(x(1),x(end),10);
y1 = interp1(x,y,x1);
quiver(x1,x1*0,abs(y1)./y1,x1*0,0.2)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!