lakshmen
lakshmen

Reputation: 29064

'x' and 'y' lengths differ in R

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.

Upvotes: 1

Views: 23669

Answers (1)

Se&#241;or O
Se&#241;or O

Reputation: 17412

To plot the horizontal line for the second derivative of the wealth utility function, you'll need to make sure Udprime has a point for every point w. There's two ways to do this:

Shortcut:

plot(cbind(w, Udprime))

More "true to the math":

Udprime = -beta * w^0

Upvotes: 4

Related Questions