When modelling the melting of snow on sea-ice, how can I create a vector, for example the density of both snow and ice, respectively, so that I can run it in a loop?
Show older comments
I am currently writing a code to model the evolution of melt-ponds on sea-ice. For simplicity, I have divided the snow and ice into 5 layers each. I am using a diffusion equation. My aim is to model the melt within a loop, so I believe I need to create vectors for constants like specific heat capacity and density for the two given mediums. The density for snow = 200 and ice = 919 (kg m-3). So I can then calculate this in the model
(dt/(rho.*c.*dz))*Q
Thank you in advance.
Accepted Answer
More Answers (1)
Well, it's easy enough to create the vectors as
rho=200*ones(5,1);
say, for snow but I'm presuming you're keeping a moving boundary layer of which layer is ice/snow in the five? Otherwise, you can always multiply any array by a constant.
So, looks like what you'll need is some logical array of
isIce=true(5,1); % initially all ice
and then keep the density vectors as something like
rho(isIce)=919; rho(~isIce)=200;
For convenience or legibility or just because you could do have
isSnow=~isIce;
with which you can avoid the not expression in the subscript expression for some legibility.
ADDENDUM
And, of course, you can get slightly more sophisticated code-wise at some loss of transparency in what is actually going on and write things like --
rho=200+719*isIce;
and each time step update the isIce logical vector then compute the new density vector.
>> isIce=rand(5,1)>0.5
isIce =
0
1
1
0
1
>> rho=200+719*isIce
rho =
200
919
919
200
919
>>
4 Comments
Make the logical vector as long as it needs be and set the values of it based on the criterion of which level is/isn't ice. Same thing as above where I randomized a length of five but the initial state would be
isIce=[false(5,1);true(5,1)];
rho=200+719*isIce;
You can, of course, also use a named variable for the two densities instead of "magic numbers". That could be something like --
rhoIce=919;
rhoSno=200;
rho=rhoSno + (rhoIce-rhoSno)*isIce;
dpb
on 18 Dec 2014
Actually seems like you'd need three states instead of only two as surely there's molten water in the mix at times, too, isn't there? If so, the same idea works except instead of just a binary logical you'll build a state vector of three values and fix up a similar interpolating/computing/lookup scheme to set the values as I used above for the binary case.
Thomas
on 18 Dec 2014
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!