Hello,

Please always write to r-help, not to me personally, even if I was able to be of assistance in the past.

As for your question, your code has several problems.

1) rowSums and colSums return vectors, not matrices. Even if they did, see point 3) below.

2) You define K = 0 then in

X[1]=1/(K*A[i,j]*c[1,1]+K*A[i,j]*c[1,2]+K*A[i,j]*c[1,3])

the denominator is zero because A[i,j] and c[] are multiplied by it.

3) What are the i,j in A[i,j] and P[i,j]?


Hope this helps,

Rui Barradas


Às 11:51 de 21-07-2018, Atanasio Alberto Tembe Tembe escreveu:
Dear Mr. Barradas,

Thank you for your attention.

Sorry for this personalized e-mail. I recently posted a query about while loop, but I did not get good feedback. I am a beginner in R and I wonder if you can me help again.

If I have two matrices such as: a<-matrix(1:9,nrow=3,ncol=3) and c<-matrix(1:9,nrow=3,ncol=3).

with defined variables:
K=0
A[i,j]=colSums(a)
P[i,j]=rowSums(a)
F[i,j]=c[i,j]^(-2 )
X[i]=A[i,j]*c[i,j]
X[j]=P[i,j]*c[i,j]

How to perform the following calculation with while loop so that it stops when a convergence between X and Y values is reached?.

X[1]=1/(K*A[i,j]*c[1,1]+K*A[i,j]*c[1,2]+K*A[i,j]*c[1,3])

Y[1]=1/(X[1]*P[i,j]*c[1,1]+[X1]*P[i,j]*c[1,2]+[X1]*P[i,j]*c[1,3])

X[2]=1/(Y[1]*A[i,j]*c[2,1]+Y[1]*A[i,j]*c[2,2]+Y[1]*A[i,j]*c[2,3])

Y[2]=1/(X[2]*P[i,j]*c[2,1]+X[2]*P[i,j]*c[2,2]+X[2]*P[i,j]*c[2,3])

X[3]=1/(Y[2]*A[i,j]*c[3,1]+Y[1]*A[i,j]*c[3,2]+Y[2]*A[i,j]*c[3,3])

Y[3]=1/(X[3]*P[3]*c[3,1]+X[3]*P[3]*c[3,2]+X[3]*P[3]*c[3,3])


Thank you very much.










On Mon, Jul 16, 2018 at 6:51 PM, Atanasio Alberto Tembe Tembe <manote...@gmail.com <mailto:manote...@gmail.com>> wrote:

    Hi Mr. Barradas,

    Thank you for your kind support. I will your suggestions.

    Best regards
    Tembe


    On Mon, Jul 16, 2018 at 6:22 PM, Rui Barradas <ruipbarra...@sapo.pt
    <mailto:ruipbarra...@sapo.pt>> wrote:

        Hello,

        Please repost in plain text, NO HTML formating.

        Also, you are missing an open parenthesis right after while:

        while( sum(abs(Sb-D-Sc-t(Pi))>1E-5)){


        Hope this helps,

        Rui Barradas


        Às 14:25 de 15-07-2018, Atanasio Alberto Tembe Tembe escreveu:

            Hello!

            Is there anyone who can help me to this the error bellow? Ijust
            started using R recently. Thank you


            while sum(abs(Sb-D-Sc-t(Pi))>1E-5{Error: unexpected symbol
            in "while
sum">     >     k=K+1>     >     for(i in 1:nrow(c1)){+    +     for(j in 1:ncol(c1)){+             +  if(Sb!=0){+
                       +                 T2=D*T/Sa+                 +
            }else {+                 +                 T2=0       +
               +             }+             +             Sc=sum(t(T))+
            +             if(Sc!=0){+                 +
T3=Pi*T2/Sc+                 +             }else {+        +
                             T3=0+                 +             }+
            Sb=sum(T)+             +         }+     }>     >     K[1] 0

                     [[alternative HTML version deleted]]

            ______________________________________________
            R-help@r-project.org <mailto:R-help@r-project.org> mailing
            list -- To UNSUBSCRIBE and more, see
            https://stat.ethz.ch/mailman/listinfo/r-help
            <https://stat.ethz.ch/mailman/listinfo/r-help>
            PLEASE do read the posting guide
            http://www.R-project.org/posting-guide.html
            <http://www.R-project.org/posting-guide.html>
            and provide commented, minimal, self-contained, reproducible
            code.




-- Atanasio Alberto Tembe (Mr)
    Doctoral student
    Graduate School of Urban Innovation
    Transportation and Urban Engineering Laboratory
    Yokohama National University
    Tel: +81-(0)80-4605-1305 <tel:+81%2080-8080-2482>
      Mail: tembe-atanasio...@ynu.jp
    <mailto:pattamaporn-wongwiriya...@ynu.jp>
    manote...@gmail.com <mailto:pattamapor...@gmail.com>




--
Atanasio Alberto Tembe (Mr)
Doctoral student
Graduate School of Urban Innovation
Transportation and Urban Engineering Laboratory
Yokohama National University
Tel: +81-(0)80-4605-1305 <tel:+81%2080-8080-2482>
  Mail: tembe-atanasio...@ynu.jp <mailto:pattamaporn-wongwiriya...@ynu.jp>
manote...@gmail.com <mailto:pattamapor...@gmail.com>

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to