Project

Effect of time step size on solution of 1-D Wave equation or 1-D Linear Convection equation solved using Windward Scheme

function [ufinal]=effectoftimestep(dt)
    L=1;
    c=1;
    n=81;
    t=0.4/dt;
    dx= L/(n-1);
    %discretizing work space

    x=linspace(0,L,n);
    u=ones(1,n);
    [H]=squarelift(x,n);
    u(H(1):H(2))=2;
    uold=u;
    uinitial=u;
        %time loop
        for j=1:t;

            %space loop
            for i=2:n;

            u(i)=uold(i)-((c*dt/dx)*(uold(i)-uold(i-1)));
            end

        uold=u;
        pause(0.000001);
        plot(x,u)
        grid on 
        axis ([0 1 0 3])
        end
    ufinal=u;

    plot(x,uinitial,x,ufinal)
    grid on
    axis([0 1 0 3])
    xlabel(\'Length domain\');
    ylabel(\'wave velocity profile\');
    legend(\'Initial velocity profile\',\'final velocity profile\');
end

\"\"

\"\"

\"\"

\"\"

The above code is of a function that takes the time step as an argument i.e. the value of time increments and solves the 1-D Wave equation or 1-D Linear Convection equation through windward scheme (for c greater than 1).

The graphs are for values final velocity profile & intial velocity profile vs the length L for dt=1e-4, 1e-3, 1e-2 & 1e-1 respectively.

The following scheme is conditionally stable at R (c*dt/dx) less than or equal to 1. Therefore, variations in the value of dt will also affect the amplification factor or R.

For dt =1e-4, 1e-3, 1e-2 the value of R is less than 1 hence the the solution is stable and the error term does not amplify with time. However, at dt=1e-1, R equals 8 and hence the solution becomes unstable. That is why the solution or our square wave distorts subsequently with time.

Also at dt=1e-2 the amplification factor is equal to 0.8 i.e closest to 1 (value at which the solution will be most accurate) hence we see that the the final velocity at the value retains the most of its squareness as compared to other plots.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.