loops - Populating large matrix with equation in R -
i trying populate matrix using 2 loops. inner loop supposed calculate 1 row (points in space) , outer loop supposed calculate next point in time each of points in space. i'm not sure how fill blank matrix made each new calculated row. here code:
l=100 #[m] s=0.01 n=0.0036 #[s/m^1/3] train=720 #[s] qrain=0.0000027 #[m/s] t=3600 #[s] dx=10 #[m] dt=0.01 #[s] n=1/dt h=matrix(,nrow=n*t,ncol=10) h[1,]=0 (j in 1:nrow(h)) { if(j<(train/dt)) q=qrain else q=0 (i in 1:ncol(h)) { h[i,j+1]=h[i,j]-(dt*s/n)*((h[(i+1),j]^(5/3)-h[i,j]^(5/3))/dx)+q } v=matrix(((s^0.5)/n)*(h^(2/3)),nrow=nrow(h),ncol=ncol(h)) } q=matrix(v*h,nrow=nrow(h),ncol=ncol(h))
is valid write equation way? want whole first row h[1,] zeros, , wants create h[1,1] 0. not sure if i'm missing obvious. in advance help! (it's first post here).
r loops for-loop matrix vector
No comments:
Post a Comment