Personal Website:
Scott Congreve

Teaching

Download<< Back

function pendfric_euler
% Comparing solving pendfric using euler with h=0.1,0.5 and ode23s
for h=[0.1 0.5]
    figure;
    hold on;    
    xlim([-10 10]);
    ylim([-3 3]);
    xlabel('x_1');
    xlabel('x_2');
    title(['h = ' num2str(h)]);
    plot(pi*(-3:3), zeros(1,7), 'b*', 'DisplayName', 'Steady States');
    
    x0=[-4; 1];
    [~,x]=ode23s(@pendfric, [0 50], x0);
    plot(x(:,1), x(:,2), '-r*');
    [~,x]=eul(@pendfric, 0, 70, x0, h);
    plot(x(:,1), x(:,2), '-k.');

    x0=[2; 2];
    [~,x]=ode23s(@pendfric, [0 50], x0);
    plot(x(:,1), x(:,2), '-r*');
    [~,x]=eul(@pendfric, 0, 70, x0, h);
    plot(x(:,1), x(:,2), '-k.');
    
    x0=[2; 1];
    [~,x]=ode23s(@pendfric, [0 50], x0);
    plot(x(:,1), x(:,2), '-r*');
    [~,x]=eul(@pendfric, 0, 70, x0, h);
    plot(x(:,1), x(:,2), '-k.');
    
    x0=[-4; 0];
    [~,x]=ode23s(@pendfric, [0 50], x0);
    plot(x(:,1), x(:,2), '-r*');
    [~,x]=eul(@pendfric, 0, 70, x0, h);
    plot(x(:,1), x(:,2), '-k.');
end

end