Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- funcprot(0)
- u = 1 //velocidade de propagação da onda
- p = 1 //periodo
- tf = 5 //tempo final
- dt = 0.008 //variação do tempo
- dx = 0.01 //variação do espaço
- C = u*(dt/dx) //número de Courant
- t = 0:dt:tf
- x = 0:dx:p
- itert = length(t)
- iterx = length(x)
- //Calculo da solução inicial a ser advectada para t=0
- fi = zeros(1,iterx)
- for i=1:iterx
- fi(i) = condInicial(0,x(i),u,p)
- end
- //Solução numérica
- Quw = upwind(fi,C,t,x)
- Qlw = lax(fi,C,t,x)
- Qbw = laxfri(fi,C,t,x)
- Qrw= leapfrog(fi,C,t,x)
- //Geração dos vetores a serem impressos para t = 1 e 5
- Qtuw = [t' Quw]
- Qtlw = [t' Qlw]
- Qtbw = [t' Qbw]
- Qtrw = [t' Qrw]
- indice = ['t'];
- for i=1:iterx
- aux = 'Q('+string(x(i))+')'
- indice = [indice aux]
- end
- Qtuw1 = [indice;string(Qtuw(126,:));string(Qtuw(626,:))]
- Qtlw1 = [indice;string(Qtlw(126,:));string(Qtlw(626,:))]
- Qtbw1 = [indice;string(Qtbw(126,:));string(Qtbw(626,:))]
- Qtrw1 = [indice;string(Qtrw(126,:));string(Qtrw(626,:))]
- //Solução análitica da equação de advecção para grafico
- vta = 0.5 //variação do tempo para solução análitica
- vxa = 0.0001 //váriação do espaço para solução análitica
- xa = 0:vxa:p
- ta = 0:vta:tf
- iterxa = length(xa)
- iterta = length(ta)
- fia = zeros(iterta, iterxa)
- for n=1:iterta
- for i=1:iterxa
- fia(n,i) = condInicial(ta(n),xa(i),u,p)
- end
- end
- figure(1)
- titulo = 'Solução Númerica com método Upwind para t = 3 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Quw(376,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
- figure(2)
- titulo = 'Solução Númerica com método Upwind para t = 5 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Quw(626,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
- figure(3)
- titulo = 'Solução Númerica com método Lax-Wendroff para t = 3 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Qlw(376,:),'colo','green','linest','--','marker','*','markeredg','green','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
- figure(4)
- titulo = 'Solução Númerica com método Lax-Wendroff para t = 5 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Qlw(626,:),'colo','green','linest','--','marker','*','markeredg','green','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
- figure(5)
- titulo = 'Solução Númerica com método Lax-Friedrichs para t = 3 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Qbw(376,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
- figure(6)
- titulo = 'Solução Númerica com método Lax-Friedrichs para t = 5 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Qbw(626,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
- figure(7)
- titulo = 'Solução Númerica com método Leapfrog para t = 3 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Qrw(376,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
- figure(8)
- titulo = 'Solução Númerica com método Leapfrog para t = 5 '
- xtitle(titulo,'x','fi(x,t)')
- plot(xa,fia(1,:),'colo','blue','linest','--')
- plot(x,Qrw(626,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
- a=get("current_axes")
- a.data_bounds=[0,-0.4;1,1.4];
- a.x_label.font_size = 4;
- a.y_label.font_size = 4;
- a.title.font_size = 4;
- a.cube_scaling = "on"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement