[R] DEfining and plotting the sum of two functions

arun smartpink111 at yahoo.com
Mon May 20 15:53:43 CEST 2013


Hi,
Try:
H<-function(x) H1(x)+H2(x)
 H1(2)
[#1] 4
H2(2)
#[1] 7
 H(2)
#[1] 11


A.K.



----- Original Message -----
From: Honest Chipoyera <Honest.Chipoyera at wits.ac.za>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Monday, May 20, 2013 8:09 AM
Subject: [R] DEfining and plotting the sum of two functions

I have two functions H1(x) and H2(x) defined separately and I wish to create a new function H(x)  which is the sum of the two functions. I also need to plot the three functions using the command "curve". With the aid of the example program below, can you please explain how I can do that in R.

H1<-function(x) x^2
H2<-function(x) x+5
H<-function(x){H1+H2}
par(mfrow=c(3,1))
curve(H1(x),0,100)
curve(H2(x),0,100)
curve(H(x),0,100)



HW Chipoyera
Cell: 0767190507


<table width="100%" border="0" cellspacing="0" cellpadding="0" style="width:100%;">
<tr>
<td align="left" style="text-align:justify;"><font face="arial,sans-serif" size="1" color="#999999"><span style="font-size:11px;">This communication is intended for the addressee only. It is confidential. If you have received this communication in error, please notify us immediately and destroy the original message. You may not copy or disseminate this communication without the permission of the University. Only authorised signatories are competent to enter into agreements on behalf of the University and recipients are thus advised that the content of this message may not be legally binding on the University and may contain the personal views and opinions of the author, which are not necessarily the views and opinions of The University of the Witwatersrand, Johannesburg. All agreements between the University and outsiders are subject to South African Law unless the University agrees in writing to the contrary. </span></font></td>
</tr>
</table

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list