How to decrease index of an vector on every time step?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Maitiumc
el 12 de Dic. de 2016
Comentada: Maitiumc
el 13 de Dic. de 2016
This seems like a fairly straight forward thing to do, however it has been giving me all sorts of trouble.
I am working on a geophysical model, and part of that involves a rainfall rate, and once surface temperatures gets to 100C, subsequent rainfall will accumulate as a reservoir. However, a fraction of this will still evaporate each timestep.
So as you can see below, during times of rainfall, the surface can reach 100C. I to plot another variable however, to show the water that has accumulated in on the surface.
The maths is a little more complex, but lets say 1% is evaporated each timestep, I simply want the reservoir to decrease by 1% each step.
I think the main issue I am having is that the water can only begin to accumulate on the surface when it has reached 100C, continues to accumulate until the rain stops and as soon as the rain stops the accummulated water value will begin to decrease. But the way I have it coded, as soon as the rain stops, the temperature increases and the water in the reservoir isn't considered.
What I am looking for, would be a plot similar in shape to the 'Total Rain' plot, but that begins to decrease once T rises, not remains constant until it rains again.
Here is the code I have:
for n = timesteps
if T(n,1)>373
T(n+1,1) = equation1; % surface temp
else
T(n+1,1) = equation2; % surface temp = 373K
rainTotalAccum = cumsum(rain);
if rainTotalAccum(n)>0
T(n+1,1) = equation2; % To try and stop T increasing once rain stops if there is surface water present
rTotalAccum(n) = rTotalAccum(n) - rTotalAccum(n)*0.01; % 1% of rain evaporated each timestep
end
end
end
What I need is a way to decrease the value of rainTotalAccum each timestep, keeping the temperature at 373K, but everything I have tried so far has failed. I'd really appreciate any advice on this.
0 comentarios
Respuesta aceptada
Kenny Kim
el 12 de Dic. de 2016
I don't have all your code so I can't be sure this is the problem but:
rTotalAccum(n) = rTotalAccum(n) - rTotalAccum(n)*0.01;
Shouldn't this be
rTotalAccum(n+1) = rTotalAccum(n) - rTotalAccum(n)*0.01;
Also you are running
T(n+1,1) = equation2;
twice and I don't think that is intentional.
3 comentarios
Kenny Kim
el 13 de Dic. de 2016
How about a format like this?
time = linspace(0,25,25*100+1); % arbitrarily chosen time vector
rain = somerandomfunction(time); % vector of rainfall at time
rainTotalAccum = nan(size(time)); %initial
rainTotalAccum(1) = 0; % initial accumulation of rain
T = nan(size(time));
T(1) = 210; % initial temperature
for n = 1:numel(time)-1
if rain(n) > 0
rainTotalAccum(n+1) = rainTotalAccum(n) + rain(n);
else
rainTotalAccum(n+1) = rainTotalAccum(n) - rainTotalAccum(n)*0.01;
end
if rainTotalAccum(n) > 0
T(n+1,1) = equation2;
else
T(n+1,1) = equation1;
end
end
The reason I chose format like this is because whether you should choose equation 2 or 1 should matter on accumulated rain, not on temperature.
Also, cumsum function adds up all of the rain that fell (even the evaporated ones), so I don't think that represents the physical phenomenon well.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!