Project

Week 5 Mid Term Project

clear allclose allclc l=1;n=20;x=linspace(0,1,n);dx=l/(n-1);u=ones(1,n);c=1;dt=0.01;u=1*u;n_start=0;n_end=0;%drawing the graph and checking the give square form% findiding the n_start and n_end value automatically even though n changesn_start =index1(u,n,x);n_end = index2(u,n,x);u(n_start:n_end)=2;uold=u;uinitial=uold;%no of time stepkt=100;%calculating the u value using explicit method%assuming at time step(n) as uold and new time step as unewfor i=1:ktfor i=2:n u(i)=uold(i)-(c*(dt/dx)*(uold(i)-uold(i-1)));enduold=ufigure (1)xlabel('x');ylabel('velocity');plot(x,u)pause(0.4)endfigure (2)plot(x,u);pause(0.4)holdplot(x,uinitial); INDEX FUNCTIONS for finding N_end value function [index_2] = index2(u,n,x)for i=1:n if x(i)>0.3 break end index_2=i; endend for finding N-start value function [index_1] = index1(u,n,x)for i=1:n if x(i)>0.1 break end index_1=iendend as this is a explicit method the error is increasing for smaller and higher no.of nodes but for the nodes like 80 or 100 the error seems to be less. The accuracy in this method varies depending upon the nodes which is not feasible. a solution must have the same accuracy independent of the no.of nodes for which implicit form is used through out eventhough it is tedious.

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.