I am trying to plot a horizontal line in R, but it is giving me an error.
Code:
w <- seq(1, 99, by=1)
alpha <- 0.1
beta <- 0.001
U <- alpha*w -(beta/2)*w*w
Uprime <- alpha -(beta)*w
Udprime <- -beta
Utprime <- 0
plot(w,Udprime,type = "l",main = "Graph of U(W) versus wealth",xlab = "Wealth",ylab = "Utility Function")
When I plot this function out, I get this error:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
Why is that so? Need some guidance.
length(w)==99andlength(Udprime)==1? I assume you meantplot(w, Uprime, ...)instead. - Joshua Ulrichw, which is constant for all values ofw. So a plot would show a horizontal line. What is it that you're trying to actually plot? - Señor Oplot(w, U)? - Señor OUdprime <- -beta + 0 * wso that it's length is the same aslength(w). - Gregor Thomas