Question
CAN YOU PLEASE DO THIS USING Rstudio CAN YOU PLEASE DO THIS USING Rstudio first_name
CAN YOU PLEASE DO THIS USING Rstudio
CAN YOU PLEASE DO THIS USING Rstudio
first_name<-'p' last_name<-'l'
###################################################################################################
#################################################################### #################################################################### #################################################################### Exercise 1 instruction # Write code to maximize the total profit for the following problem. # # A firm sells products A and B at $20 and $30 respectively. # Let x be the number of units produced for A and y be the number of units produced for B. # Assume the firm can sell everything it produces. # # Product A cost = 10 + x^2/10 # Product B cost = 5 + y^2/5 # # There is also a handling cost = xy/50 # # 1a write a function for the profit if the firm produces x units of A and y units of B # 1b use R function nlminb to find the pair of (x,y) that maximizes the profits. # # put your result in 'optimal1'
profit<-function(decision) { #decision is a vector consist of x and y x<-decision[1] y<-decision[2] revenue<-20*x+30*y production.cost<-10+x^2/10+5+y^2/5 handling.cost<-x*y/50 profit<-revenue - production.cost - handling.cost -profit }
optimal1<-nlminb(c(0,0),profit)
###### keep below code result1<- -optimal1$objective output1<-data.frame(last_name,first_name,result1) output1$'question' <- 1
#################################################################### #################################################################### #################################################################### Exercise 2 instruction
########################################### run below simulation code set.seed(nchar(first_name)+nchar(last_name)) x <- sample(0:5000, 500, replace=TRUE) e <- sample(0:500, 500, replace=TRUE) df <- data.frame(matrix(NA, nrow = 500, ncol = 0)) df$'y' <- (nchar(last_name))*(x+e)+e df$'x' <- x #######################
# 2. consider regression model y = b0 + b1*x + e # 2a write a function to calculate the least square for this equation. Make sure the data is probably pass into this function # 2b use the R function nlminb to find b0 and b1 that minmizes the least squares using above datafram "df". Put the result in 'optimal2'
###### keep below code result2<-optimal2$par output2<-data.frame(last_name,first_name,optimal2$par) output2$'question' <- 2
I have also pasted the code into PASTEBIN for easier access
https://pastebin.com/2a1B3cTg
I JUST NEED HELP WITH PART TWO OF THIS PROBELM ONLY NEED HELP WITH #2 OF THIS PROBLEM WHICH IS HIGHLIGHTED IN BOLD
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started