Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an R function pwfun ( ) , which computes values of the piece - wise ( mathematical ) function pwfun defined in the following

Create an R function pwfun(), which computes values of the piece-wise (mathematical) function pwfun
defined in the following way:
pwfun()=22021,<1,1<=<=1,1<
Its graph is as follows.
Your R function pwfun() should also accept x as a vector of arbitrary length and return vector of the same length with entries defined as values of the mathematical function pwfun
, evaluated at the corresponding entries of vector x.
Here are some input vectors and what you should get as a corresponding output.
pwfun(-1)
0
pwfun(c(-2,0.5,3))
208
x = c(-3,-2,-1,0,1,2,3.2)
pwfun(x)
4200039.24
Hint:
Obviously, one way to solve this is using if-elseif-else statment. Apart from that, you can also take a look at the R function ifelse(), which you could call twice.
Be careful: because R has assignment operator <-, code lines a <-1 and a <-1 do NOT have the same meaning!
While a <-1 checks whether variable a is less than -1,
a <-1 means the same as a <-1, which is assigning the value 1 to the variable a.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

Express each number in terms of j. 121

Answered: 1 week ago

Question

Make arguments for the union and for the employer.

Answered: 1 week ago