Dear Sir/Madam, I hope you will be fine. I am new to R language. Recently, I am trying to fit my data with one model. I am sending you the code and image file on which you can see the error I am receiving instead of executing. If I give a single value to parameter "ep", it executes well, but if I make a loop/seq for getting a range of data it shows error.I need you help in solving this problem. Thanking in advance, With Best Regards, Dawood -------------- next part -------------- A non-text attachment was scrubbed... Name: CodeImage.png Type: image/png Size: 177372 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150504/2cc619b1/attachment.png>
Need Help!
5 messages · dawood ahmad, Boris Steipe, Kehl Dániel
Dear Dawood,
it is not a really good idea to open a new email with the same problem you already posted earlier.
I see you accepted some suggestions (HTML, seq) but not others (pi is a defined constant in R, do not change it, type pi ENTER to see this.). I would like to add one more, c is a function, do not use it as a variable name (I used cc instead of c).
I tried to figure out what you want here. The following code might do what you want. It gives you a feeling about how you would create a basic loop. There are nicer ways to do that in R. Note the [i]-s in the for loop!
cc <- 0.5
xc <- 2
s <- 6
Hc2 <- 30
H <- 1
ep<-seq(0.01, 0.49, by=0.001)
res <- numeric(length=length(ep))
for (i in 1:length(ep)){
f<-function(k) 1.211*10^(-6)*Hc2/H*(trigamma( ((ep[i] + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)) - trigamma(((cc + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)))
res[i] <- integrate(f,-pi/s,pi/s)$value
}
Best,
daniel
________________________________________
Felad?: R-help [r-help-bounces at r-project.org] ; meghatalmazó: dawood ahmad [dawoodmalik at hotmail.com]
K?ldve: 2015. m?jus 4. 10:29
To: r-help at R-project.org
T?rgy: [R] Need Help!
Dear Sir/Madam,
I hope you will be fine. I am new to R language. Recently, I am trying to fit my data with one model.
I am sending you the code and image file on which you can see the error I am receiving instead of executing.
If I give a single value to parameter "ep", it executes well, but if I make a loop/seq for getting a range of data it shows
error.I need you help in solving this problem.
Thanking in advance,
With Best Regards,
Dawood
Dear Daniel, Thank you very much for such a kind reply. Actually, I couldn't understand well the criteria of help list, I am sorry for that. I tried you method, unfortunately I couldn't get the output. It may be due to my lack of expertise in programming. At this point I need your help which will mean a lot to me. Moreover, if I use single value it gives the output. I am sending you two image files of the outputs. I will be really grateful to you if you guide me. Thanking in advance, With Best Regards, Dawood
From: kehld at ktk.pte.hu
To: dawoodmalik at hotmail.com; r-help at r-project.org
Subject: RE: [R] Need Help!
Date: Mon, 4 May 2015 20:17:48 +0000
Dear Dawood,
it is not a really good idea to open a new email with the same problem you already posted earlier.
I see you accepted some suggestions (HTML, seq) but not others (pi is a defined constant in R, do not change it, type pi ENTER to see this.). I would like to add one more, c is a function, do not use it as a variable name (I used cc instead of c).
I tried to figure out what you want here. The following code might do what you want. It gives you a feeling about how you would create a basic loop. There are nicer ways to do that in R. Note the [i]-s in the for loop!
cc <- 0.5
xc <- 2
s <- 6
Hc2 <- 30
H <- 1
ep<-seq(0.01, 0.49, by=0.001)
res <- numeric(length=length(ep))
for (i in 1:length(ep)){
f<-function(k) 1.211*10^(-6)*Hc2/H*(trigamma( ((ep[i] + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)) - trigamma(((cc + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)))
res[i] <- integrate(f,-pi/s,pi/s)$value
}
Best,
daniel
________________________________________ Felad?: R-help [r-help-bounces at r-project.org] ; meghatalmazó: dawood ahmad [dawoodmalik at hotmail.com] K?ldve: 2015. m?jus 4. 10:29 To: r-help at R-project.org T?rgy: [R] Need Help! Dear Sir/Madam, I hope you will be fine. I am new to R language. Recently, I am trying to fit my data with one model. I am sending you the code and image file on which you can see the error I am receiving instead of executing. If I give a single value to parameter "ep", it executes well, but if I make a loop/seq for getting a range of data it shows error.I need you help in solving this problem. Thanking in advance, With Best Regards, Dawood
-------------- next part -------------- A non-text attachment was scrubbed... Name: Page1.png Type: image/png Size: 493197 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150505/4f6c1882/attachment-0002.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: Page2.png Type: image/png Size: 451492 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150505/4f6c1882/attachment-0003.png>
For crying out loud Dawood - can you please stop posting screenshots? Do you not know how to copy your output and paste it into the body of a (not HTML formatted!) email? Let us know if you need help with that. B.
On May 5, 2015, at 11:05 AM, dawood ahmad <dawoodmalik at hotmail.com> wrote:
Dear Daniel, Thank you very much for such a kind reply. Actually, I couldn't understand well the criteria of help list, I am sorry for that. I tried you method, unfortunately I couldn't get the output. It may be due to my lack of expertise in programming. At this point I need your help which will mean a lot to me. Moreover, if I use single value it gives the output. I am sending you two image files of the outputs. I will be really grateful to you if you guide me. Thanking in advance, With Best Regards, Dawood
From: kehld at ktk.pte.hu
To: dawoodmalik at hotmail.com; r-help at r-project.org
Subject: RE: [R] Need Help!
Date: Mon, 4 May 2015 20:17:48 +0000
Dear Dawood,
it is not a really good idea to open a new email with the same problem you already posted earlier.
I see you accepted some suggestions (HTML, seq) but not others (pi is a defined constant in R, do not change it, type pi ENTER to see this.). I would like to add one more, c is a function, do not use it as a variable name (I used cc instead of c).
I tried to figure out what you want here. The following code might do what you want. It gives you a feeling about how you would create a basic loop. There are nicer ways to do that in R. Note the [i]-s in the for loop!
cc <- 0.5
xc <- 2
s <- 6
Hc2 <- 30
H <- 1
ep<-seq(0.01, 0.49, by=0.001)
res <- numeric(length=length(ep))
for (i in 1:length(ep)){
f<-function(k) 1.211*10^(-6)*Hc2/H*(trigamma( ((ep[i] + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)) - trigamma(((cc + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)))
res[i] <- integrate(f,-pi/s,pi/s)$value
}
Best,
daniel
________________________________________ Felad?: R-help [r-help-bounces at r-project.org] ; meghatalmazó: dawood ahmad [dawoodmalik at hotmail.com] K?ldve: 2015. m?jus 4. 10:29 To: r-help at R-project.org T?rgy: [R] Need Help! Dear Sir/Madam, I hope you will be fine. I am new to R language. Recently, I am trying to fit my data with one model. I am sending you the code and image file on which you can see the error I am receiving instead of executing. If I give a single value to parameter "ep", it executes well, but if I make a loop/seq for getting a range of data it shows error.I need you help in solving this problem. Thanking in advance, With Best Regards, Dawood
<Page1.png><Page2.png>______________________________________________
R-help at 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.
Hi, type res #<ENTER> (now it contains your results as a vector) or head(res) #so you only see the first couple of values or plot(res) #to see a basic plot (you could set axis labels etc, but I suggets you to go ahead and read a tutorial on R! Best, have a great time with R, kd ________________________________ Felad?: dawood ahmad [dawoodmalik at hotmail.com] K?ldve: 2015. m?jus 5. 17:05 To: Kehl D?niel; r-help at R-project.org T?rgy: RE: [R] Need Help! Dear Daniel, Thank you very much for such a kind reply. Actually, I couldn't understand well the criteria of help list, I am sorry for that. I tried you method, unfortunately I couldn't get the output. It may be due to my lack of expertise in programming. At this point I need your help which will mean a lot to me. Moreover, if I use single value it gives the output. I am sending you two image files of the outputs. I will be really grateful to you if you guide me. Thanking in advance, With Best Regards, Dawood
From: kehld at ktk.pte.hu
To: dawoodmalik at hotmail.com; r-help at r-project.org
Subject: RE: [R] Need Help!
Date: Mon, 4 May 2015 20:17:48 +0000
Dear Dawood,
it is not a really good idea to open a new email with the same problem you already posted earlier.
I see you accepted some suggestions (HTML, seq) but not others (pi is a defined constant in R, do not change it, type pi ENTER to see this.). I would like to add one more, c is a function, do not use it as a variable name (I used cc instead of c).
I tried to figure out what you want here. The following code might do what you want. It gives you a feeling about how you would create a basic loop. There are nicer ways to do that in R. Note the [i]-s in the for loop!
cc <- 0.5
xc <- 2
s <- 6
Hc2 <- 30
H <- 1
ep<-seq(0.01, 0.49, by=0.001)
res <- numeric(length=length(ep))
for (i in 1:length(ep)){
f<-function(k) 1.211*10^(-6)*Hc2/H*(trigamma( ((ep[i] + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)) - trigamma(((cc + H/Hc2 + (2*xc/s)^2*(1 - cos(k*s))/2)/2*Hc2/H)))
res[i] <- integrate(f,-pi/s,pi/s)$value
}
Best,
daniel
________________________________________ Felad?: R-help [r-help-bounces at r-project.org] ; meghatalmazó: dawood ahmad [dawoodmalik at hotmail.com] K?ldve: 2015. m?jus 4. 10:29 To: r-help at R-project.org T?rgy: [R] Need Help! Dear Sir/Madam, I hope you will be fine. I am new to R language. Recently, I am trying to fit my data with one model. I am sending you the code and image file on which you can see the error I am receiving instead of executing. If I give a single value to parameter "ep", it executes well, but if I make a loop/seq for getting a range of data it shows error.I need you help in solving this problem. Thanking in advance, With Best Regards, Dawood