Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Mastering Scientific Computing with R
  • Table Of Contents Toc
Mastering Scientific Computing with R

Mastering Scientific Computing with R

By : Paul Gerrard
3.6 (7)
close
close
Mastering Scientific Computing with R

Mastering Scientific Computing with R

3.6 (7)
By: Paul Gerrard

Overview of this book

If you want to learn how to quantitatively answer scientific questions for practical purposes using the powerful R language and the open source R tool ecosystem, this book is ideal for you. It is ideally suited for scientists who understand scientific concepts, know a little R, and want to be able to start applying R to be able to answer empirical scientific questions. Some R exposure is helpful, but not compulsory.
Table of Contents (12 chapters)
close
close
11
Index

General non-linear optimization


You may be interested in solving general non-linear optimization problems where the constraints are not linear. The solnp() function from the Rsolnp package allows you to solve general non-linear programming problems. For example, say we wanted to minimize the function subject to the constraint .

First, we install and load the package as follows:

> install.packages("Rsolnp")
> library("Rsolnp")

# We also suggest taking a look at the help page for the function arguments and restriction
> help(solnp) 

Then, we store our function to minimize f as follows:

> f <- function(x){
   4*x[1] - 2*x[2]
 }

We need to store our constraint function in a separate object as follows:

> ctr <- function(x){
   x[1]^2 + x[2]^2
 }

Next, we store the value on the right-hand side of the constraint equation in a separate object as follows:

> constraints <- c(41)

Then, we store the initial parameters for and in x0 as follows:

> x0 <- c(1, 1)

We are ready to...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Mastering Scientific Computing with R
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon