function examplebif clear all close all ts = 0; te = 10; rr = [-4:0.01:4]; xr = [-2:0.01:2]; xI = 0.1; [r,x] = meshgrid(rr,xr); % generate grid points in [p,x] fval = feval(@fcn,r,x); % evaluate the points value figure(1); [c,h] = contour(r,x,fval,[0,0],'r'); % plot the zero contour line set(gca,'fontsize',20); set(h,'linewidth',2); xlabel('r'), ylabel('x*') grid on; N = length(rr); N2 = floor(N/2); for i = N2:N sol = ode45(@rhs,[ts te],xI,[],rr(i)); figure(2); plot(sol.x,sol.y,'linewidth',2); set(gca,'fontsize',20); xlabel('t'); ylabel('x'); grid on; rs(i) = rr(i); ys(i) = sol.y(end); end; figure(1); hold on; h=plot(rs,ys,'o'); set(h,'linewidth',2); set(gca,'fontsize',20); grid on; xlabel('r'); ylabel('x*'); title('dx = r - x^2'); sol1 = ode45(@rhs,[ts 23],xI,[],rr(floor(N/2))); rsU = rr(floor(N/2)); ysU = sol.y(end); figure(2);clf; h=plot(sol1.x,sol1.y); set(h,'linewidth',2); set(gca,'fontsize',20); xlabel('t'); ylabel('x'); grid on; function f = fcn(r,x) f = r - x.^2; function dx = rhs(t,x,r) dx = r - x.^2;