functionexamples

# functionexamples - b1= c"True""False"...

This preview shows page 1. Sign up to view the full content.

fun2<-function(x1,a1=100,b1=-.05){ res1<-a1*(1-exp(b1*x1)) return(res1) } fun2(20) fun2(20,a1=90,b1=-0.07) ####This above code temporarily overrides the values for a1 & b1#### fun3<-function(x1){ f1<-(7/10*sqrt(6*pi))+3/(10*sqrt(2*pi)) f1<-f1*exp(-1/18*(x1-3)^2-1/2*(x1-8)^2) return(f1) } ####Below code shows how to find the integral of the function#### intfun3<-function(a1=0,b1=1,delta1=0.1){ x1<-seq(a1,b1,by= delta1) return(res1) } intfun3(a1=2,b1=5,delta1=0.1) intfun3(a1=2,b1=5,delta1=0.01) ####Below code shows creating a list to return more than 1 value#### x1<-list(a1=c(1,2,3,4,5),
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: b1= c("True","False"), c1=c(1.983,2.425,3.334) ) ####If you want to see the names of items on a list, use the names() statement#### ####Below code is a function that returns a list#### fun2list<-function(y1,x1,a1=3,b1=.5){ pred1<-a1+b1*x1 resid1<-y1-pred1 MSE1<-sum(resid1^2)/length(x1-2) res1<-list(predicted=pred1, residuals=resid1, MSE=MSE1) return(res1) } ####Running code#### x1<-seq(0,10,by=1) y1<-c(3.03,3.51,4.06,4.46,5.01,5.53,5.93,6.51,7.07,7.44,8.05) fun2list(y1,x1,a1=3,b1=.5) f1a<-fun2list(y1,x1,a1=3,b1=.5) f1a\$MSE f1a\$predicted...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern