[R] DEfining and plotting the sum of two functions

Berend Hasselman bhh at xs4all.nl
Mon May 20 15:49:57 CEST 2013


On 20-05-2013, at 14:09, Honest Chipoyera <Honest.Chipoyera at wits.ac.za> wrote:

> 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)


You correctly use H1(x) and H2(x) in the curve calls.
Why don't you use H1(x)+H2(x) in function H?

H<-function(x){H1(x)+H2(x)}

Berend


> 
> HW Chipoyera
> Cell: 0767190507

Please post in  plain text as the Posting Guide asks you to do.

> <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