Graph f(x) = 1/x

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Graph f(x) = 1/x

AbouEl-Makarim Aboueissa-3
Dear All: good morning

I am trying to graph the function y=f(x)=1/x over the interval (-5,5). But
I am getting an error message. Please see below.

I am getting the error message: *Error in xy.coords(x, y, xlabel, ylabel,
log) : *
*  'x' and 'y' lengths differ*


x

x <- seq(-5, 5, 0.01)
y < 1/x

plot(x,y, type='l', xlim=c(-5, 5), ylim=c(-5, 5), xlab = "x", ylab = "f(x)
= 1/x", lwd = 2, col ="red")

abline(h=0, lty=2, col = "blue")
abline(v=0, lty=2, col = "blue")
axis(1)
axis(2)
title(main="The Graph of f(x) = 1/x")


any help will be highly appreciated.


with thanks
abou
______________________
AbouEl-Makarim Aboueissa, PhD
Professor of Statistics
Department of Mathematics and Statistics
University of Southern Maine

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Graph f(x) = 1/x

Achim Zeileis-4


On Tue, 19 Sep 2017, AbouEl-Makarim Aboueissa wrote:

> Dear All: good morning
>
> I am trying to graph the function y=f(x)=1/x over the interval (-5,5). But
> I am getting an error message. Please see below.
>
> I am getting the error message: *Error in xy.coords(x, y, xlabel, ylabel,
> log) : *
> *  'x' and 'y' lengths differ*

You have "y < 1/x" rather than "y <- 1/x"! So "y" is not assigned and
presumably you have some old "y" variable in your global environment that
is used and does not match the length of "x".

>
> x
>
> x <- seq(-5, 5, 0.01)
> y < 1/x
>
> plot(x,y, type='l', xlim=c(-5, 5), ylim=c(-5, 5), xlab = "x", ylab = "f(x)
> = 1/x", lwd = 2, col ="red")
>
> abline(h=0, lty=2, col = "blue")
> abline(v=0, lty=2, col = "blue")
> axis(1)
> axis(2)
> title(main="The Graph of f(x) = 1/x")
>
>
> any help will be highly appreciated.
>
>
> with thanks
> abou
> ______________________
> AbouEl-Makarim Aboueissa, PhD
> Professor of Statistics
> Department of Mathematics and Statistics
> University of Southern Maine
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Graph f(x) = 1/x

AbouEl-Makarim Aboueissa-3
Dear Zeileis:

Thank you very much

abou

On Tue, Sep 19, 2017 at 4:13 AM, Achim Zeileis <[hidden email]>
wrote:

>
>
> On Tue, 19 Sep 2017, AbouEl-Makarim Aboueissa wrote:
>
> Dear All: good morning
>>
>> I am trying to graph the function y=f(x)=1/x over the interval (-5,5). But
>> I am getting an error message. Please see below.
>>
>> I am getting the error message: *Error in xy.coords(x, y, xlabel, ylabel,
>> log) : *
>> *  'x' and 'y' lengths differ*
>>
>
> You have "y < 1/x" rather than "y <- 1/x"! So "y" is not assigned and
> presumably you have some old "y" variable in your global environment that
> is used and does not match the length of "x".
>
>
>> x
>>
>> x <- seq(-5, 5, 0.01)
>> y < 1/x
>>
>> plot(x,y, type='l', xlim=c(-5, 5), ylim=c(-5, 5), xlab = "x", ylab = "f(x)
>> = 1/x", lwd = 2, col ="red")
>>
>> abline(h=0, lty=2, col = "blue")
>> abline(v=0, lty=2, col = "blue")
>> axis(1)
>> axis(2)
>> title(main="The Graph of f(x) = 1/x")
>>
>>
>> any help will be highly appreciated.
>>
>>
>> with thanks
>> abou
>> ______________________
>> AbouEl-Makarim Aboueissa, PhD
>> Professor of Statistics
>> Department of Mathematics and Statistics
>> University of Southern Maine
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>


--
______________________
AbouEl-Makarim Aboueissa, PhD
Professor of Statistics
Department of Mathematics and Statistics
University of Southern Maine

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Graph f(x) = 1/x

Ivan Calandra-5
It's always good to start a new session when you don't understand what's
wrong, because sometimes your code is correct, but you use old data
without knowing it :)

Ivan

--
Dr. Ivan Calandra
TraCEr, Laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra

On 19/09/2017 10:19, AbouEl-Makarim Aboueissa wrote:

> Dear Zeileis:
>
> Thank you very much
>
> abou
>
> On Tue, Sep 19, 2017 at 4:13 AM, Achim Zeileis <[hidden email]>
> wrote:
>
>>
>> On Tue, 19 Sep 2017, AbouEl-Makarim Aboueissa wrote:
>>
>> Dear All: good morning
>>> I am trying to graph the function y=f(x)=1/x over the interval (-5,5). But
>>> I am getting an error message. Please see below.
>>>
>>> I am getting the error message: *Error in xy.coords(x, y, xlabel, ylabel,
>>> log) : *
>>> *  'x' and 'y' lengths differ*
>>>
>> You have "y < 1/x" rather than "y <- 1/x"! So "y" is not assigned and
>> presumably you have some old "y" variable in your global environment that
>> is used and does not match the length of "x".
>>
>>
>>> x
>>>
>>> x <- seq(-5, 5, 0.01)
>>> y < 1/x
>>>
>>> plot(x,y, type='l', xlim=c(-5, 5), ylim=c(-5, 5), xlab = "x", ylab = "f(x)
>>> = 1/x", lwd = 2, col ="red")
>>>
>>> abline(h=0, lty=2, col = "blue")
>>> abline(v=0, lty=2, col = "blue")
>>> axis(1)
>>> axis(2)
>>> title(main="The Graph of f(x) = 1/x")
>>>
>>>
>>> any help will be highly appreciated.
>>>
>>>
>>> with thanks
>>> abou
>>> ______________________
>>> AbouEl-Makarim Aboueissa, PhD
>>> Professor of Statistics
>>> Department of Mathematics and Statistics
>>> University of Southern Maine
>>>
>>>          [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Graph f(x) = 1/x

Rui Barradas
In reply to this post by AbouEl-Makarim Aboueissa-3
Hello,

I believe that the easiest way is

curve(1/x, -5, 5)

Also, you're missing a '-' in y < 1/x, it should be y <- 1/x

Hope this helps,

Rui Barradas



Citando AbouEl-Makarim Aboueissa <[hidden email]>:

> Dear All: good morning
>
> I am trying to graph the function y=f(x)=1/x over the interval (-5,5). But
> I am getting an error message. Please see below.
>
> I am getting the error message: *Error in xy.coords(x, y, xlabel, ylabel,
> log) : *
> *  'x' and 'y' lengths differ*
>
>
> x
>
> x <- seq(-5, 5, 0.01)
> y < 1/x
>
> plot(x,y, type='l', xlim=c(-5, 5), ylim=c(-5, 5), xlab = "x", ylab = "f(x)
> = 1/x", lwd = 2, col ="red")
>
> abline(h=0, lty=2, col = "blue")
> abline(v=0, lty=2, col = "blue")
> axis(1)
> axis(2)
> title(main="The Graph of f(x) = 1/x")
>
>
> any help will be highly appreciated.
>
>
> with thanks
> abou
> ______________________
> AbouEl-Makarim Aboueissa, PhD
> Professor of Statistics
> Department of Mathematics and Statistics
> University of Southern Maine
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.