Hi
first of all few comments
Does your email client have subject line? If yes please use it, if not, change
the client.
Please do not post in HTML, such emails have big chance to be scrambled.
# this gives you 10 random numbers
x<-rnorm(10,0,1)
f<-fuction(u,x) {exp(x- u)}
# you probably ment
f<-function(u,x) {exp(x- u)}
for(i in 1:lenght(x) integrate(f,lower=1,upper=4)
# you probably ment
for(i in 1:length(x)) integrate(f,lower=1,upper=4)
......................^^...^
but this gives you an error> for(i in 1:length(x)) integrate(f,lower=1,upper=4)
Error in f(x, ...) : argument "x" is missing, with no default
The error message comes from your f function as you did not defined u
If you changed your f function somehow
f<-function(x, u=2) {exp(x - u)}
for(i in 1:length(x)) integrate(f,lower=1,upper=4)
the error is gone but so do results.
You need either print your results explicitly or to assign them to some object.
But if you printed your results you would find that you get same repeated result
length(x) times.> for(i in 1:length(x)) print(integrate(f,lower=1,upper=4))
7.021177 with absolute error < 7.8e-14
7.021177 with absolute error < 7.8e-14
7.021177 with absolute error < 7.8e-14
7.021177 with absolute error < 7.8e-14
7.021177 with absolute error < 7.8e-14
AFAIK, integrate computes area below curve defined by function f between lower
and upper and it has nothing to do with your x definition.
So you should reconsider what do you want to achieve and if you have some time
you should read some introduction document(s) to understand how R operates with
objects. R Intro should be good starting point.
Cheers
Petr
> -----Original Message-----
> From: R-help <r-help-bounces at r-project.org> On Behalf Of malika
yassa via R-
> help
> Sent: Saturday, October 20, 2018 3:04 PM
> To: r-help at r-project.org
> Subject: [R] (no subject)
>
> hello
> please you help mei have this functionx<-rnorm(10,0,1)f<-fuction(u,x)
{exp((x-
> u)}I want to calculate the integral of this function for each value of
x{for(i in
> 1:lenght(x)
> integrate(f,lower=1,upper=4)
>
> }but I can not find the vector of resulatwhere is the errorthinks
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch
partner? PRECHEZA a.s. jsou zve?ejn?ny na:
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about
processing and protection of business partner?s personal data are available on
website: https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a
podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti:
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to
it may be confidential and are subject to the legally binding disclaimer:
https://www.precheza.cz/en/01-disclaimer/