Question

1. Consider the function y - f(x) defined by Supposing that you are given x, write an R expression for y using if state- ments. Add your , then run it to plot the function jf # input x.values <- seq(-2, 2, by - 0.1) expression for y to the following program # for each x calculate y n <- length(x.values) y.values <- rep(0, n) for (i in 1:n) t x <- x.values [i] # your expression for y goes here y.values[i] <- y # output plot(x,values, y.values, type 1) =

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The complete required code:

# input
x.values <- seq(-2, 2, by = 0.1)

# for each x calculate y
n <- length(x.values)
y.values <- rep(0,n)
for(i in 1:n){
   x <-x.values[i]
   if(x <= 0){
       y <- -(x^3)
   }
   if( x > 0 && x <=1){
       y <- x^2
   }
   if(x >1){
       y <- sqrt(x)
   }
   y.values[i] <-y
}

# output
plot(x.values, y.values, type="l")

Add a comment
Know the answer?
Add Answer to:
1. Consider the function y - f(x) defined by Supposing that you are given x, write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT