0

I'm writting a code to solve the "equation of advection", which express how a given property or physical quantity varies with time. For that I've this expression: https://gyazo.com/f531cb756ffbd3ec28ab85ea1f09b18d This is one of my issues, I dont know how to implement it. This is the code I've for the moment:

    %%Our paramatres 

k = 1e-4; 
x = [1 2 2.1 13.9 14 28 28.1 39.9 40 59 69 79 150];
y = [3000 3000 3150 3150 3000 3000 3080 3080 3000 3000 3150 3000 3000];
vx = 0.1; % velocity in x m/s
tmax = 250; %time max
xmin = min(x);
xmax = max(x);
axis([0 150 2990 3160])
plot(x,y,'--')

%% discretization of domain
%
dx = 150;
dt = dx/(5*vx); % delta time is equal delta x * vx
n = tmax / dt ;
m = (xmax - xmin)/dx;
x = linspace(xmin,xmax,m+1); % é igual a x = xmin:dx:xmax
%% Stability condition
%
lambda = k * dt/vx^2;
while lambda > 1/2
    fprintf ('Satisfied\n\n')
    fprintf ('Value of dt is %5.1f and for z is %i \n\n', dt,dx)
    dt = input('New value for dt: ')
    dx = input ('New value for dx: ')
    lambda = k*dt/dx^2;
    n = tmax/dt;
    m = xmax/dx;
    x = linspace(xmin,xmax,m+1);
end
%%Initial conditions and frontier
%
h = zeros(size(x));
h(x>0)=1;
plot(x,h)
xlabel('Distance')
ylabel('Density')
grid on

1 Answers1

0

You could use ode45 for first order diff eq. http://www.mathworks.com/help/matlab/ref/ode45.html

Or

Make it a simple linear eq. That solve it with matrix inverse multiplication \.

If the equation is not solveble, calculate the Moore–Penrose pseudoinverse with pinvthe http://www.mathworks.com/help/matlab/ref/pinv.html.

bni i
  • 103
  • 7
  • I can't make it simple. I've to use that equation to solve the problem. https://gyazo.com/1cda55c7e8f557895d4bd5e1689572e2 Those polygons are made with the x and the y. Then with that equation it should be like those curves. – Renato Dimas Dec 17 '15 at 16:24